fix(parser): reparse all statements with await identifier in unambiguous mode#18163
fix(parser): reparse all statements with await identifier in unambiguous mode#18163
Conversation
…ous mode Commit 92e27b4 only handled `await /regex/` but missed `await (...)` and other cases where `await` followed by certain tokens was parsed as an identifier instead of an await expression. This change follows TypeScript's approach by tracking ALL identifiers named "await" and reparsing affected statements when ESM syntax is detected. Changes: - Add `encountered_await_identifier` flag to ParserState - Set flag when parsing "await" as identifier in non-await context - Track checkpoints only for statements that actually used await as identifier - Once ESM detected, enable await context for remaining statements Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes parsing of await identifiers in unambiguous mode by extending the previous fix (commit 92e27b4) that only handled await /regex/ to cover other cases like await (...) and await in declarations.
Changes:
- Added
encountered_await_identifierflag to track whenawaitis parsed as an identifier in non-await contexts - Modified statement parsing to checkpoint and reparse statements containing await identifiers when ESM syntax is detected
- Added test cases for
await (...)call expressions andawaitin variable declarations
Reviewed changes
Copilot reviewed 3 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_parser/src/state.rs | Adds encountered_await_identifier flag to track await identifier usage |
| crates/oxc_parser/src/js/statement.rs | Implements checkpoint tracking and reparsing logic for statements with await identifiers |
| crates/oxc_parser/src/js/expression.rs | Sets flag when parsing await as identifier in non-await contexts |
| tasks/coverage/misc/pass/unambiguous-await-call.js | Test case for await (...) expression |
| tasks/coverage/misc/pass/unambiguous-await-in-declaration.js | Test case for await in variable declarations |
| tasks/coverage/snapshots/*.snap | Updated test snapshots reflecting improved parsing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merging this PR will not alter performance
Comparing Footnotes
|
Summary
await (...)and other cases whereawaitfollowed by certain tokens was parsed as an identifier instead of an await expression in unambiguous modeawait /regex/but missed other casesChanges
encountered_await_identifierflag toParserStateto track when await is parsed as identifierparse_identifier_referencewhen parsing "await" as identifier in non-await contextTest plan
tasks/coverage/misc/pass/:unambiguous-await-call.js- Testsawait (async function () { })();unambiguous-await-in-declaration.js- Testsconst x = await (async function () { })();🤖 Generated with Claude Code