From be2c60dd10ce8e4cf78d1470036b8400d003b64c Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Sat, 21 Dec 2024 10:20:14 +0000 Subject: [PATCH] fix(parser): parse `import source from from 'mod'` (#8056) --- crates/oxc_parser/src/js/module.rs | 4 +--- tasks/coverage/snapshots/parser_test262.snap | 12 ++---------- tasks/coverage/snapshots/semantic_test262.snap | 5 +---- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/crates/oxc_parser/src/js/module.rs b/crates/oxc_parser/src/js/module.rs index 2ef147e0515d3..275cbf6657986 100644 --- a/crates/oxc_parser/src/js/module.rs +++ b/crates/oxc_parser/src/js/module.rs @@ -60,9 +60,7 @@ impl<'a> ParserImpl<'a> { let mut phase = None; match self.cur_kind() { Kind::Source => { - let peek_kind = self.peek_kind(); - // Allow `import source from 'mod'` - if peek_kind.is_binding_identifier() && peek_kind != Kind::From { + if self.peek_kind().is_binding_identifier() && self.nth_kind(2) == Kind::From { self.bump_any(); phase = Some(ImportPhase::Source); } diff --git a/tasks/coverage/snapshots/parser_test262.snap b/tasks/coverage/snapshots/parser_test262.snap index ae844dc37ac1c..d7080e7e330f7 100644 --- a/tasks/coverage/snapshots/parser_test262.snap +++ b/tasks/coverage/snapshots/parser_test262.snap @@ -1,17 +1,9 @@ commit: c4317b0c parser_test262 Summary: -AST Parsed : 44100/44101 (100.00%) -Positive Passed: 44100/44101 (100.00%) +AST Parsed : 44101/44101 (100.00%) +Positive Passed: 44101/44101 (100.00%) Negative Passed: 4454/4454 (100.00%) -Expect to Parse: tasks/coverage/test262/test/language/module-code/source-phase-import/import-source-binding-name-2.js - - × Unexpected token - ╭─[test262/test/language/module-code/source-phase-import/import-source-binding-name-2.js:23:20] - 22 │ import source source from ''; - 23 │ import source from from ''; - · ──── - ╰──── × '0'-prefixed octal literals and octal escape sequences are deprecated ╭─[test262/test/annexB/language/expressions/template-literal/legacy-octal-escape-sequence-strict.js:19:4] diff --git a/tasks/coverage/snapshots/semantic_test262.snap b/tasks/coverage/snapshots/semantic_test262.snap index cf6bee31971e5..d2107edbb972e 100644 --- a/tasks/coverage/snapshots/semantic_test262.snap +++ b/tasks/coverage/snapshots/semantic_test262.snap @@ -2,7 +2,7 @@ commit: c4317b0c semantic_test262 Summary: AST Parsed : 44101/44101 (100.00%) -Positive Passed: 43582/44101 (98.82%) +Positive Passed: 43583/44101 (98.83%) tasks/coverage/test262/test/annexB/language/function-code/if-decl-else-decl-a-func-block-scoping.js semantic error: Symbol scope ID mismatch for "f": after transform: SymbolId(3): ScopeId(4294967294) @@ -3633,9 +3633,6 @@ Unresolved references mismatch: after transform: ["$DONE", "Object", "assert", "require"] rebuilt : ["$DONE", "Object", "_superprop_getMethod", "assert", "require"] -tasks/coverage/test262/test/language/module-code/source-phase-import/import-source-binding-name-2.js -semantic error: Unexpected token - tasks/coverage/test262/test/language/module-code/top-level-await/syntax/for-await-await-expr-func-expression.js semantic error: Scope children mismatch: after transform: ScopeId(14): [ScopeId(1)]