Skip to content

JS: Allow await/yield as property names - #22518

Closed
redsun82 wants to merge 3 commits into
mainfrom
redsun82-js-await-property-parse-error
Closed

JS: Allow await/yield as property names#22518
redsun82 wants to merge 3 commits into
mainfrom
redsun82-js-await-property-parse-error

Conversation

@redsun82

@redsun82 redsun82 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

await is a perfectly valid property name, even inside an async function, but the JavaScript extractor rejected pool.await() with Can not use 'await' as identifier inside an async function, aborting extraction of the whole file. The same applied to yield inside a generator.

In jcorn's parseIdent, the reserved-word check is guarded by !liberal, but the yield/await checks were only guarded by !isPrivateField. liberal is exactly the "this is a property name, not a binding" flag, passed by member-expression parsing and by parsePropertyName, so property names, object literal keys and class method names all wrongly triggered the error. Upstream acorn runs both checks from checkUnreserved, which only fires when !liberal; this change aligns with that. Shorthand properties ({ await }) are rejected by a separate check in parseProperty, so they still error correctly.

Tests:

  • AwaitYieldIdentifierTests covers the accepted property-name forms and the still-rejected binding/reference forms.
  • extractor/tests/es2017/await-yield-property.js pins the extraction end to end. Verified it is a real regression test: with the fix reverted, the trap golden loses the whole AST and keeps only tokens, and TrapTests fails.

Fixes: #22499

redsun82 and others added 2 commits September 7, 2026 10:19
`parseIdent` guarded the reserved-word check with `!liberal` but the
`yield`/`await` checks only with `!isPrivateField`, so property names
such as `pool.await()` were rejected inside an `async` function. Acorn
runs both from `checkUnreserved`, which only fires when `!liberal`.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 7, 2026 08:43
@redsun82
redsun82 requested review from a team as code owners September 7, 2026 08:43
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

Copilot review overview

🟡 Changes recommended

Liberal parsing also covers decorator references, unintentionally allowing restricted bare identifiers there.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 1 Medium severity · 1 Low severity

New issues introduced by this change (2)
Severity Finding
Medium severity javascript/​extractor/​src/​com/​semmle/​jcorn/​Parser.javaliberal is not limited to property names: ESNextParser.parseDecoratorBody passes true when…
Low severity javascript/​extractor/​src/​com/​semmle/​jcorn/​Parser.java — The implication here is reversed: isPrivateField requires liberal, but ordinary liberal…
What changed in this PR

Fixes the JavaScript extractor to allow await and yield as property names while retaining identifier restrictions.

Changes:

  • Updates parseIdent handling.
  • Adds parser and end-to-end regression tests.
  • Documents the fix.
File Description
javascript/​ql/​lib/​change-notes/​2026-09-07-await-property.md Records the parser fix.
javascript/​extractor/​tests/​es2017/​input/​await-yield-property.js Adds extraction input coverage.
javascript/​extractor/​tests/​es2017/​output/​trap/​await-yield-property.js.trap Pins expected extraction output.
javascript/​extractor/​test/​com/​semmle/​js/​extractor/​test/​AwaitYieldIdentifierTests.java Tests accepted properties and rejected identifiers.
javascript/​extractor/​test/​com/​semmle/​js/​extractor/​test/​AllTests.java Registers the new test class.
javascript/​extractor/​src/​com/​semmle/​jcorn/​Parser.java Relaxes contextual-keyword validation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +2301 to +2303
if (!liberal && this.inGenerator && this.value.equals("yield"))
this.raiseRecoverable(this.start, "Can not use 'yield' as identifier inside a generator");
if (!isPrivateField && this.inAsync && this.value.equals("await"))
if (!liberal && this.inAsync && this.value.equals("await"))
Comment on lines +2299 to +2300
// `yield` and `await` are only restricted as bindings and references, not as property
// names, which is what `liberal` indicates (it also implies `isPrivateField`).
@redsun82

redsun82 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

already fixed in #22500

@redsun82 redsun82 closed this Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CodeQL confused by property named "await" in JavaScript code

2 participants