Skip to content

Commit

Permalink
fix(parser): parse import source from 'mod' (#7833)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Dec 13, 2024
1 parent e4d0405 commit 7610dc1
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/actions/clone-submodules/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ runs:
show-progress: false
repository: tc39/test262
path: tasks/coverage/test262
ref: eefc5cf367b999768445432e167606fd1acf1734
ref: dc0082c5ea347e5ecb585c1d7ebf4555aa429528

- uses: actions/checkout@v4
with:
Expand Down
10 changes: 7 additions & 3 deletions crates/oxc_parser/src/js/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ impl<'a> ParserImpl<'a> {
let mut import_kind = ImportOrExportKind::Value;
let mut phase = None;
match self.cur_kind() {
Kind::Source if self.peek_kind().is_binding_identifier() => {
self.bump_any();
phase = Some(ImportPhase::Source);
Kind::Source => {
let peek_kind = self.peek_kind();
// Allow `import source from 'mod'`
if peek_kind.is_binding_identifier() && peek_kind != Kind::From {
self.bump_any();
phase = Some(ImportPhase::Source);
}
}
Kind::Defer if self.peek_at(Kind::Star) => {
self.bump_any();
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ready:
# Clone or update submodules
# Make sure to update `.github/actions/clone-submodules/action.yml` too
submodules:
just clone-submodule tasks/coverage/test262 https://github.com/tc39/test262.git eefc5cf367b999768445432e167606fd1acf1734
just clone-submodule tasks/coverage/test262 https://github.com/tc39/test262.git dc0082c5ea347e5ecb585c1d7ebf4555aa429528
just clone-submodule tasks/coverage/babel https://github.com/babel/babel.git 54a8389fa31ce4fd18b0335b05832dc1ad3cc21f
just clone-submodule tasks/coverage/typescript https://github.com/microsoft/TypeScript.git d85767abfd83880cea17cea70f9913e9c4496dcc
just clone-submodule tasks/prettier_conformance/prettier https://github.com/prettier/prettier.git 37fd1774d13ef68abcc03775ceef0a91f87a57d7
Expand Down
6 changes: 3 additions & 3 deletions tasks/coverage/snapshots/codegen_test262.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
commit: eefc5cf3
commit: dc0082c5

codegen_test262 Summary:
AST Parsed : 44169/44169 (100.00%)
Positive Passed: 44169/44169 (100.00%)
AST Parsed : 44096/44096 (100.00%)
Positive Passed: 44096/44096 (100.00%)
6 changes: 3 additions & 3 deletions tasks/coverage/snapshots/minifier_test262.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
commit: eefc5cf3
commit: dc0082c5

minifier_test262 Summary:
AST Parsed : 44169/44169 (100.00%)
Positive Passed: 44169/44169 (100.00%)
AST Parsed : 44096/44096 (100.00%)
Positive Passed: 44096/44096 (100.00%)
38 changes: 9 additions & 29 deletions tasks/coverage/snapshots/parser_test262.snap
Original file line number Diff line number Diff line change
@@ -1,38 +1,18 @@
commit: eefc5cf3
commit: dc0082c5

parser_test262 Summary:
AST Parsed : 44166/44169 (99.99%)
Positive Passed: 44166/44169 (99.99%)
AST Parsed : 44095/44096 (100.00%)
Positive Passed: 44095/44096 (100.00%)
Negative Passed: 4454/4456 (99.96%)
Expect Syntax Error: tasks/coverage/test262/test/language/import/import-attributes/json-invalid.js
Expect Syntax Error: tasks/coverage/test262/test/language/import/import-attributes/json-named-bindings.js
Expect to Parse: tasks/coverage/test262/test/language/import/import-defer/errors/resolution-error/import-defer-of-missing-module-fails.js
Expect to Parse: tasks/coverage/test262/test/language/module-code/source-phase-import/import-source-binding-name-2.js

× Expected `from` but found `string`
╭─[test262/test/language/import/import-defer/errors/resolution-error/import-defer-of-missing-module-fails.js:22:22]
21 │
22 │ import defer * as ns "./resolution-error_FIXTURE.js";
· ───────────────┬───────────────
· ╰── `from` expected
╰────
Expect to Parse: tasks/coverage/test262/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js

× Expected `from` but found `string`
╭─[test262/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js:22:22]
21 │
22 │ import defer * as ns "./syntax-error_FIXTURE.js";
· ─────────────┬─────────────
· ╰── `from` expected
╰────
Expect to Parse: tasks/coverage/test262/test/language/module-code/source-phase-import/import-source-binding-name.js

× Expected `from` but found `string`
╭─[test262/test/language/module-code/source-phase-import/import-source-binding-name.js:22:20]
21 │
22 │ import source from '<do not resolve>';
· ─────────┬────────
· ╰── `from` expected
23 │ import from from '<do not resolve>';
× Unexpected token
╭─[test262/test/language/module-code/source-phase-import/import-source-binding-name-2.js:23:20]
22 │ import source source from '<do not resolve>';
23 │ import source from from '<do not resolve>';
· ────
╰────

× '0'-prefixed octal literals and octal escape sequences are deprecated
Expand Down
2 changes: 1 addition & 1 deletion tasks/coverage/snapshots/runtime.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
commit: eefc5cf3
commit: dc0082c5

runtime Summary:
AST Parsed : 18055/18055 (100.00%)
Expand Down
16 changes: 5 additions & 11 deletions tasks/coverage/snapshots/semantic_test262.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
commit: eefc5cf3
commit: dc0082c5

semantic_test262 Summary:
AST Parsed : 44169/44169 (100.00%)
Positive Passed: 43640/44169 (98.80%)
AST Parsed : 44096/44096 (100.00%)
Positive Passed: 43569/44096 (98.80%)
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)
Expand Down Expand Up @@ -3695,14 +3695,8 @@ Unresolved references mismatch:
after transform: ["$DONE", "Object", "assert", "require"]
rebuilt : ["$DONE", "Object", "_superprop_getMethod", "assert", "require"]

tasks/coverage/test262/test/language/import/import-defer/errors/resolution-error/import-defer-of-missing-module-fails.js
semantic error: Expected `from` but found `string`

tasks/coverage/test262/test/language/import/import-defer/errors/syntax-error/import-defer-of-syntax-error-fails.js
semantic error: Expected `from` but found `string`

tasks/coverage/test262/test/language/module-code/source-phase-import/import-source-binding-name.js
semantic error: Expected `from` but found `string`
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:
Expand Down
6 changes: 3 additions & 3 deletions tasks/coverage/snapshots/transformer_test262.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
commit: eefc5cf3
commit: dc0082c5

transformer_test262 Summary:
AST Parsed : 44169/44169 (100.00%)
Positive Passed: 44169/44169 (100.00%)
AST Parsed : 44096/44096 (100.00%)
Positive Passed: 44096/44096 (100.00%)
1 change: 1 addition & 0 deletions tasks/coverage/src/test262/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl<T: Case> Suite<T> for Test262Suite<T> {

fn skip_test_path(&self, path: &Path) -> bool {
let path = path.to_string_lossy();
path.contains("test262/test/staging") ||
// ignore markdown files
path.ends_with(".md") ||
// ignore fixtures
Expand Down

0 comments on commit 7610dc1

Please sign in to comment.