Repository navigation
JS: Fix parsing of destructuring patterns with identifiers named set or get - #22918
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The unchanged extractor version allows existing TRAP cache entries to reuse stale parse-error output, bypassing the parser fix.
1 open issue
What changed in this PR
Fixes CodeQL’s JavaScript parser so destructuring bindings named get or set can have default values without being mistaken for accessors.
Changes:
- Excludes
=from getter/setter detection. - Adds regression cases for destructuring defaults while checking that accessors and methods still parse.
- Updates expected extraction output.
| File | Description |
|---|---|
javascript/extractor/tests/es2015/output/trap/property_pattern_with_default.js.trap |
Updates expected output for the expanded tests. |
javascript/extractor/tests/es2015/input/property_pattern_with_default.js |
Adds destructuring, accessor, and method regression cases. |
javascript/extractor/src/com/semmle/jcorn/Parser.java |
Prevents default-value syntax from triggering accessor parsing. |
Review effort: Max
| && (this.type != TokenType.comma && this.type != TokenType.braceR)) { | ||
| && (this.type != TokenType.comma | ||
| && this.type != TokenType.braceR | ||
| && this.type != TokenType.eq)) { |
Contributor
Author
There was a problem hiding this comment.
@asgerf :til:! I haven't done this for previous JS extractor fixes. Is this something I should fixup for this PR and start doing going forward?
Contributor
There was a problem hiding this comment.
No need. TRAP caching has been superseded by overlay support.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The JS parser currently fails to parse:
Luckily, the fix is pretty simple and a version is already present in acornjs/acorn.
Commit-by-commit review recommended.