fix(parser): preserve fatal errors during await reparse (#25541)

Fixes #23681.

Preserve initial fatal parser errors during top-level `await` reparsing, preventing malformed recovery AST nodes from reaching Oxlint.

Validated with parser unit/conformance suites and allocation snapshots. `just ready` only fails three unrelated ANSI snapshot checks in the current environment.

AI-assisted.
This commit is contained in:
Boshen committed 2026-08-12 11:25:27 +00:00
1 parent 460aa50b7d
commit 73acba93fb
3 files changed
+15 -2

No files matched your search

+3 -1
View File
@@ -809,7 +809,9 @@ impl<'a, C: ParserConfig> ParserImpl<'a, C> {
// we need to reparse statements that were originally parsed with `await` as identifier.
// TypeScript's behavior: initially parse `await /x/` as division, then reparse as
// await expression with regex when ESM is detected.
if self.source_type.is_unambiguous()
// Preserve a fatal error from the initial parse instead of rewinding past it.
if self.fatal_error.is_none()
&& self.source_type.is_unambiguous()
&& self.module_record_builder.has_module_syntax()
&& !self.state.potential_await_reparse.is_empty()
{
+4
View File
@@ -0,0 +1,4 @@
await
foo();
var prefix = 'fas';
export()s.height = height;
+8 -1
View File
@@ -1,7 +1,7 @@
parser_misc Summary:
AST Parsed : 77/77 (100.00%)
Positive Passed: 77/77 (100.00%)
Negative Passed: 159/159 (100.00%)
Negative Passed: 160/160 (100.00%)
× Cannot assign to 'arguments' in strict mode
╭─[misc/fail/arguments-eval-ambient.ts:2:13]
@@ -3805,6 +3805,13 @@ Negative Passed: 159/159 (100.00%)
╰────
help: Wrap this with parenthesis
× Unexpected token
╭─[misc/fail/oxc-23681.js:4:7]
3 │ var prefix = 'fas';
4 │ export()s.height = height;
· ─
╰────
× Expected 'with' in import type options
╭─[misc/fail/oxc-2394.ts:20:22]
19 │ export type LocalInterface =