Skip to content

JS: Require binding identifier after await using - #23040

Open
sam-robson wants to merge 1 commit into
mainfrom
sam-robson/js-await-using-call
Open

sam-robson wants to merge 1 commit into
mainfrom
sam-robson/js-await-using-call

Conversation

@sam-robson

@sam-robson sam-robson commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Check that await using (and using in for loop initializers) is followed by an identifier on the same line before parsing it as a declaration, so calls like await using(...) parse as expressions.

@sam-robson
sam-robson force-pushed the sam-robson/js-await-using-call branch from 681ab26 to 0f912db Compare November 6, 2026 10:05
@github-actions github-actions Bot added the JS label Nov 6, 2026
@sam-robson
sam-robson force-pushed the sam-robson/js-await-using-call branch from 0f912db to d4eb971 Compare November 6, 2026 10:28
@sam-robson
sam-robson marked this pull request as ready for review November 6, 2026 11:53
@sam-robson
sam-robson requested review from a team as code owners November 6, 2026 11:53
Copilot AI auto review requested due to automatic review settings November 6, 2026 11:53

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 new using lookahead mishandles escaped and astral identifiers, valid JavaScript whitespace, and embedded line terminators, causing declarations to be incorrectly accepted or rejected.

3 open issues
What changed in this PR

This PR updates the JavaScript extractor to distinguish resource declarations from expressions such as await using(...) by checking for a following binding identifier on the same line.

Changes:

  • Reuses declaration lookahead for await using and using in loop initializers.
  • Adds an awaited-call regression fixture and updates its expected AST.
File Description
javascript/​ql/​test/​library-tests/​AST/​ExplicitResource/​tst.js Adds an await using("foo") expression case.
javascript/​ql/​test/​library-tests/​AST/​ExplicitResource/​printAst.expected Records the expected awaited-call AST.
javascript/​extractor/​src/​com/​semmle/​jcorn/​Parser.java Shares binding lookahead across await and loop declaration checks.

Review effort: Balanced (auto)

Comment on lines 2635 to +2636
Matcher m = Whitespace.skipWhiteSpace.matcher(this.input);
m.find(this.pos);
m.find(pos);
int next = m.end();
return this.input.length() > next &&
!Whitespace.lineBreakG.matcher(inputSubstring(this.pos, next)).matches()
!Whitespace.lineBreakG.matcher(inputSubstring(pos, next)).matches()
return this.input.length() > next &&
!Whitespace.lineBreakG.matcher(inputSubstring(this.pos, next)).matches()
!Whitespace.lineBreakG.matcher(inputSubstring(pos, next)).matches()
&& Identifiers.isIdentifierChar(this.input.codePointAt(next), false);

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants