Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/oxc_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,11 @@ impl<'a, C: ParserConfig> ParserImpl<'a, C> {
let original_tokens =
if self.lexer.config.tokens() { Some(self.lexer.take_tokens()) } else { None };

// `rewind` resets `self.fatal_error` to each checkpoint's value, all taken before any later
// statement could fail. Reparsing only re-derives already-valid `await` statements, so a
// fatal error from a later statement must survive it. Hold it aside, restore below.
let fatal_error = self.fatal_error.take();

let checkpoints = std::mem::take(&mut self.state.potential_await_reparse);
for (stmt_index, checkpoint) in checkpoints {
// Rewind to the checkpoint
Expand All @@ -833,6 +838,9 @@ impl<'a, C: ParserConfig> ParserImpl<'a, C> {
if let Some(original_tokens) = original_tokens {
self.lexer.set_tokens(original_tokens);
}

// A fatal error from reparsing comes earlier in source order and wins; else restore.
self.fatal_error = self.fatal_error.take().or(fatal_error);
}

fn default_context(source_type: SourceType, options: ParseOptions) -> Context {
Expand Down
1 change: 1 addition & 0 deletions tasks/coverage/misc/fail/oxc-23673.js

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you add #23671, #23681 as new test files and validate that they're working as expected? (if they're not, don't include those files), and let us know 🙂

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
await(E);import
7 changes: 6 additions & 1 deletion tasks/coverage/snapshots/parser_misc.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
parser_misc Summary:
AST Parsed : 69/69 (100.00%)
Positive Passed: 69/69 (100.00%)
Negative Passed: 149/149 (100.00%)
Negative Passed: 150/150 (100.00%)

× Cannot assign to 'arguments' in strict mode
╭─[misc/fail/arguments-eval.ts:1:10]
Expand Down Expand Up @@ -3602,6 +3602,11 @@ Negative Passed: 149/149 (100.00%)
· ─────────
╰────

× Expected `from` but found `EOF`
╭─[misc/fail/oxc-23673.js:2:1]
1 │ await(E);import
╰────

× Expected 'with' in import type options
╭─[misc/fail/oxc-2394.ts:20:22]
19 │ export type LocalInterface =
Expand Down
Loading