Skip to content

Drop statements a top-level await reparse consumed to the end of the file - #64993

Draft
Will Cory (roninjin10) wants to merge 1 commit into
microsoft:mainfrom
roninjin10:fix-reparse-top-level-await-eof
Draft

Will Cory (roninjin10) wants to merge 1 commit into
microsoft:mainfrom
roninjin10:fix-reparse-top-level-await-eof

Conversation

@roninjin10

@roninjin10 Will Cory (roninjin10) commented Oct 28, 2026 •

Copy link
Copy Markdown

Fixes #64999

Problem. In a module, reparseTopLevelAwait reparses the statements that may contain await in an await context, and a reparsed statement can read past its span. When the reparse reached the end of the file, the function still copied the original statements after the last span it had advanced to. For

export {}; await + f(const 0 await !x

the source file keeps an ExpressionStatement for x at [36, 37) beside the reparsed statement at [10, 37), which already contains x. TypeScript 6.0.3's JavaScript parser also produces overlapping statements on this input, so this is not a port regression.

Change. Once the reparse reaches the end of the file, no original statement is left to copy or reparse, so reparseTopLevelAwait stops there.

Tests. TestReparseTopLevelAwaitThroughEndOfFile fails without the change (statement 2 [36, 37) overlaps statement 1 [10, 37)) and passes with it. go test ./internal/parser/ passes, and so do the 440 TestLocal subtests of the compiler and conformance tests whose names contain await. npx hereby validate --all has not been run.

Found by fuzzing the parser with a sibling-order invariant (each node starts at or after the end of its previous sibling) in a fork of this repository.

This patch was written by Claude Code (Claude Opus 5.5), disclosed as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

…file

When a module's statements that may contain `await` are reparsed in an
await context, a reparsed statement can read past the span it started in.
If the reparse reached the end of the file, reparseTopLevelAwait still
copied the original statements after the last span it had advanced to, so
the source file kept statements overlapping the reparsed one: in
`export {}; await + f(const 0 await !x`, `x` was both inside the reparsed
call and a statement of its own.

Once the reparse reaches the end of the file, no original statement is left
to copy or reparse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@roninjin10

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="Tevm Inc"

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

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Top-level await reparse keeps statements it already consumed when it reaches the end of the file

1 participant