Skip to content

JS: Fix parsing of destructuring patterns with identifiers named set or get - #22918

Merged
MathiasVP merged 3 commits into
github:mainfrom
MathiasVP:fix-js-parsing-set-get
Oct 29, 2026
Merged

MathiasVP merged 3 commits into
github:mainfrom
MathiasVP:fix-js-parsing-set-get

Conversation

@MathiasVP

Copy link
Copy Markdown
Contributor

The JS parser currently fails to parse:

const example = ({ set = {}, unset = [] }, replacements) => {
  //             ^ Unexpected token at the '='
  return { set, unset };
};

Luckily, the fix is pretty simple and a version is already present in acornjs/acorn.

Commit-by-commit review recommended.

@MathiasVP MathiasVP added JS no-change-note-required This PR does not need a change note labels Oct 28, 2026
@MathiasVP
MathiasVP marked this pull request as ready for review October 29, 2026 07:28
Copilot AI max review requested due to automatic review settings October 29, 2026 07:28
@MathiasVP
MathiasVP requested review from a team as code owners October 29, 2026 07:28

@asgerf asgerf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need. TRAP caching has been superseded by overlay support.

@MathiasVP
MathiasVP merged commit 748b492 into github:main Oct 29, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

JS no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants