From 1bc08e296e6bfbe3b4365563bb3fc5a243178428 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Sat, 7 Sep 2024 10:48:59 +0000 Subject: [PATCH] fix(coverage): parse babel unambiguously (#5579) --- crates/oxc_transformer/src/options/babel.rs | 6 +- tasks/coverage/codegen_misc.snap | 4 +- tasks/coverage/misc/pass/babel-16776-m.js | 5 ++ tasks/coverage/misc/pass/babel-16776-s.js | 3 + tasks/coverage/parser_babel.snap | 62 +++++++++++++-------- tasks/coverage/parser_misc.snap | 12 +++- tasks/coverage/semantic_babel.snap | 29 ++++++++-- tasks/coverage/semantic_misc.snap | 7 ++- tasks/coverage/src/babel/mod.rs | 11 ++-- tasks/coverage/transformer_misc.snap | 4 +- 10 files changed, 103 insertions(+), 40 deletions(-) create mode 100644 tasks/coverage/misc/pass/babel-16776-m.js create mode 100644 tasks/coverage/misc/pass/babel-16776-s.js diff --git a/crates/oxc_transformer/src/options/babel.rs b/crates/oxc_transformer/src/options/babel.rs index 1ac839bfd5d81..7616691515754 100644 --- a/crates/oxc_transformer/src/options/babel.rs +++ b/crates/oxc_transformer/src/options/babel.rs @@ -102,7 +102,11 @@ impl BabelOptions { } pub fn is_module(&self) -> bool { - self.source_type.as_ref().map_or(false, |s| matches!(s.as_str(), "module" | "unambiguous")) + self.source_type.as_ref().map_or(false, |s| matches!(s.as_str(), "module")) + } + + pub fn is_unambiguous(&self) -> bool { + self.source_type.as_ref().map_or(false, |s| s.as_str() == "unambiguous") } /// Returns diff --git a/tasks/coverage/codegen_misc.snap b/tasks/coverage/codegen_misc.snap index 68945daf9caea..84323535ec9e6 100644 --- a/tasks/coverage/codegen_misc.snap +++ b/tasks/coverage/codegen_misc.snap @@ -1,3 +1,3 @@ codegen_misc Summary: -AST Parsed : 27/27 (100.00%) -Positive Passed: 27/27 (100.00%) +AST Parsed : 29/29 (100.00%) +Positive Passed: 29/29 (100.00%) diff --git a/tasks/coverage/misc/pass/babel-16776-m.js b/tasks/coverage/misc/pass/babel-16776-m.js new file mode 100644 index 0000000000000..48cf5e07464bc --- /dev/null +++ b/tasks/coverage/misc/pass/babel-16776-m.js @@ -0,0 +1,5 @@ +await /x.y/g; + +export { } + +var x, g; diff --git a/tasks/coverage/misc/pass/babel-16776-s.js b/tasks/coverage/misc/pass/babel-16776-s.js new file mode 100644 index 0000000000000..ccbb7f54ee39e --- /dev/null +++ b/tasks/coverage/misc/pass/babel-16776-s.js @@ -0,0 +1,3 @@ +await /x.y/g; + +var x, g; diff --git a/tasks/coverage/parser_babel.snap b/tasks/coverage/parser_babel.snap index 6c2205a0f28b9..2ca93a0ecd6ef 100644 --- a/tasks/coverage/parser_babel.snap +++ b/tasks/coverage/parser_babel.snap @@ -1,9 +1,9 @@ commit: 3bcfee23 parser_babel Summary: -AST Parsed : 2093/2101 (99.62%) -Positive Passed: 2083/2101 (99.14%) -Negative Passed: 1382/1493 (92.57%) +AST Parsed : 2089/2101 (99.43%) +Positive Passed: 2079/2101 (98.95%) +Negative Passed: 1381/1493 (92.50%) Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/3.1-sloppy-labeled-functions-if-body/input.js Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-labeled-inside-if/input.js Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-labeled-inside-loop/input.js @@ -27,6 +27,7 @@ Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2018/object-rest-spread/no-pattern-in-rest-with-ts/input.js Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2020/dynamic-import/invalid-trailing-comma/input.js Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2020/dynamic-import-createImportExpression-false/invalid-trailing-comma/input.js +Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2020/import-meta/error-in-script/input.js Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/invalid-param-strict-mode/input.js Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/esprima/es2015-generator/generator-parameter-binding-property-reserved/input.js Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0101/input.js @@ -115,6 +116,20 @@ Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/ty Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/tuple-labeled-invalid-optional/input.ts Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/tuple-optional-invalid/input.ts Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/tuple-required-after-labeled-optional/input.ts +Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-html-comments-close/input.js + + × Unexpected token + ╭─[babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-html-comments-close/input.js:1:3] + 1 │ -->b; + · ─ + ╰──── +Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/comments/html/first-line/input.js + + × Unexpected token + ╭─[babel/packages/babel-parser/test/fixtures/comments/html/first-line/input.js:1:8] + 1 │ /**/ --> comment + · ─ + ╰──── Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/core/opts/allowNewTargetOutsideFunction-true/input.js × Unexpected new.target expression @@ -132,6 +147,22 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/core/o · ────────── ╰──── help: new.target is only allowed in constructors and functions invoked using thew `new` operator +Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/core/uncategorised/343/input.js + + × Unexpected token + ╭─[babel/packages/babel-parser/test/fixtures/core/uncategorised/343/input.js:2:4] + 1 │ x = y-->10; + 2 │ --> nothing + · ─ + ╰──── +Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/core/uncategorised/538/input.js + + × Unexpected token + ╭─[babel/packages/babel-parser/test/fixtures/core/uncategorised/538/input.js:1:2] + 1 │