Skip to content

fix(parser): reparse all statements with await identifier in unambiguous mode#18163

Merged
Boshen merged 1 commit intomainfrom
fix/parser-await-reparse-all-statements
Jan 18, 2026
Merged

fix(parser): reparse all statements with await identifier in unambiguous mode#18163
Boshen merged 1 commit intomainfrom
fix/parser-await-reparse-all-statements

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Jan 18, 2026

Summary

  • Fix parsing of await (...) and other cases where await followed by certain tokens was parsed as an identifier instead of an await expression in unambiguous mode
  • Commit 92e27b4 only handled await /regex/ but missed other cases

Changes

  • Add encountered_await_identifier flag to ParserState to track when await is parsed as identifier
  • Set flag in parse_identifier_reference when parsing "await" as identifier in non-await context
  • Modify statement parsing to track checkpoints only for statements that actually used await as identifier
  • Once ESM detected, enable await context for remaining statements

Test plan

  • Added test cases in tasks/coverage/misc/pass/:
    • unambiguous-await-call.js - Tests await (async function () { })();
    • unambiguous-await-in-declaration.js - Tests const x = await (async function () { })();
  • All parser tests pass
  • All conformance tests pass

🤖 Generated with Claude Code

…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>
Copilot AI review requested due to automatic review settings January 18, 2026 02:16
@github-actions github-actions bot added A-parser Area - Parser C-bug Category - Bug labels Jan 18, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_identifier flag to track when await is 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 and await in 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.

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 18, 2026

Merging this PR will not alter performance

✅ 42 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing fix/parser-await-reparse-all-statements (57e3184) with main (c98e5b7)2

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (5f5ff1b) during the generation of this report, so c98e5b7 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Boshen Boshen merged commit 91126a0 into main Jan 18, 2026
35 checks passed
@Boshen Boshen deleted the fix/parser-await-reparse-all-statements branch January 18, 2026 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-parser Area - Parser C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants