Skip to content

fix(parser): support top-level await detection in unambiguous mode#18457

Closed
Boshen wants to merge 1 commit intomainfrom
feat/tla-unambiguous-mode
Closed

fix(parser): support top-level await detection in unambiguous mode#18457
Boshen wants to merge 1 commit intomainfrom
feat/tla-unambiguous-mode

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Jan 23, 2026

Summary

  • Add support for detecting ES modules via top-level await in unambiguous parsing mode, conforming with Babel's behavior
  • In unambiguous mode, when await <expr> is encountered at the top level and the expression is unambiguous, the file is detected as an ES module
  • Fixes Script mode parsing where await at top level should always be an identifier

Ambiguous tokens after await (following Babel's isAmbiguousPrefixOrIdentifier())

These tokens don't definitively indicate ESM:

  • +, - (unary vs binary operators)
  • (, [ (call/member vs grouped expression)
  • / (regex vs division)
  • % (modulo operator)
  • ; (semicolon - empty await)
  • Template literals
  • of, using (contextual keywords)
  • Newlines (ASI boundary)

Results

All 4 Babel TLA unambiguous tests now pass:

  • module - TLA with ESM
  • ambiguous-script - TLA with ambiguous tokens (Script detected)
  • ambiguous-modulo - TLA with % operator
  • ambiguous-v8intrinsinc - TLA with V8 intrinsic

Conformance improvements:

  • minifier_babel: 100% ✅
  • transformer_misc: 100% ✅

🤖 Generated with Claude Code

Add support for detecting ES modules via top-level await in unambiguous
parsing mode, conforming with Babel's behavior.

In unambiguous mode, when `await <expr>` is encountered at the top level
and the expression is unambiguous (not an ambiguous token), the file is
detected as an ES module.

Ambiguous tokens after `await` that don't definitively indicate ESM:
- `+`, `-` (unary vs binary operators)
- `(`, `[` (call/member vs grouped expression)
- `/` (regex vs division)
- `%` (modulo operator)
- `;` (semicolon - empty await)
- Template literals
- `of`, `using` (contextual keywords)
- Newlines (ASI boundary)

Also fixes Script mode parsing where `await` at top level should always
be an identifier (not a keyword), preventing `await / 0 / u` from being
incorrectly parsed as `await /0/u` (await + regex).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions github-actions bot added A-linter Area - Linter A-parser Area - Parser C-enhancement Category - New feature or request labels Jan 23, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 23, 2026

Merging this PR will not alter performance

✅ 42 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing feat/tla-unambiguous-mode (bf515e2) with main (7cb53ce)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 (85903cd) during the generation of this report, so 7cb53ce was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Boshen Boshen changed the title feat(parser): support top-level await detection in unambiguous mode fix(parser): support top-level await detection in unambiguous mode Jan 23, 2026
@github-actions github-actions bot added the C-bug Category - Bug label Jan 23, 2026
@graphite-app graphite-app bot closed this in 993fd2b Jan 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter A-parser Area - Parser C-bug Category - Bug C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant