mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(coverage): parse babel unambiguously (#5579)
This commit is contained in:
parent
43933912ce
commit
1bc08e296e
10 changed files with 103 additions and 40 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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%)
|
||||
|
|
|
|||
5
tasks/coverage/misc/pass/babel-16776-m.js
Normal file
5
tasks/coverage/misc/pass/babel-16776-m.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
await /x.y/g;
|
||||
|
||||
export { }
|
||||
|
||||
var x, g;
|
||||
3
tasks/coverage/misc/pass/babel-16776-s.js
Normal file
3
tasks/coverage/misc/pass/babel-16776-s.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
await /x.y/g;
|
||||
|
||||
var x, g;
|
||||
|
|
@ -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 │ <!--
|
||||
· ─
|
||||
2 │ ;
|
||||
╰────
|
||||
Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/arrow-function/generic-tsx-babel-7/input.ts
|
||||
|
||||
× Expected `<` but found `EOF`
|
||||
|
|
@ -5026,12 +5057,6 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
|
|||
· ──────────
|
||||
╰────
|
||||
|
||||
× Cannot use export statement outside a module
|
||||
╭─[babel/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-export-async-function/input.js:1:1]
|
||||
1 │ export \u0061sync function y() { await x }
|
||||
· ──────
|
||||
╰────
|
||||
|
||||
× Keywords cannot contain escape characters
|
||||
╭─[babel/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-export-dflt-async-function/input.js:1:16]
|
||||
1 │ export default \u0061sync function y() { await x }
|
||||
|
|
@ -5533,13 +5558,6 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
|
|||
· ─
|
||||
╰────
|
||||
|
||||
× Unexpected import.meta expression
|
||||
╭─[babel/packages/babel-parser/test/fixtures/es2020/import-meta/error-in-script/input.js:1:11]
|
||||
1 │ const x = import.meta;
|
||||
· ───────────
|
||||
╰────
|
||||
help: import.meta is only allowed in module code
|
||||
|
||||
× The only valid meta property for import is import.meta
|
||||
╭─[babel/packages/babel-parser/test/fixtures/es2020/import-meta/no-other-prop-names/input.js:1:1]
|
||||
1 │ import.notMeta;
|
||||
|
|
@ -7354,10 +7372,10 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
|
|||
· ───────────
|
||||
╰────
|
||||
|
||||
× Cannot use export statement outside a module
|
||||
╭─[babel/packages/babel-parser/test/fixtures/esprima/es2015-identifier/invalid_expression_await/input.js:1:1]
|
||||
× The keyword 'await' is reserved
|
||||
╭─[babel/packages/babel-parser/test/fixtures/esprima/es2015-identifier/invalid_expression_await/input.js:1:21]
|
||||
1 │ export var answer = await + 1;
|
||||
· ──────
|
||||
· ─────
|
||||
╰────
|
||||
|
||||
× Invalid Character `🀒`
|
||||
|
|
@ -7379,10 +7397,10 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
|
|||
╰────
|
||||
help: Try insert a semicolon here
|
||||
|
||||
× Cannot use export statement outside a module
|
||||
╭─[babel/packages/babel-parser/test/fixtures/esprima/es2015-identifier/invalid_var_await/input.js:1:1]
|
||||
× The keyword 'await' is reserved
|
||||
╭─[babel/packages/babel-parser/test/fixtures/esprima/es2015-identifier/invalid_var_await/input.js:1:12]
|
||||
1 │ export var await;
|
||||
· ──────
|
||||
· ─────
|
||||
╰────
|
||||
|
||||
× Expected `from` but found `default`
|
||||
|
|
|
|||
|
|
@ -1,7 +1,15 @@
|
|||
parser_misc Summary:
|
||||
AST Parsed : 27/27 (100.00%)
|
||||
Positive Passed: 27/27 (100.00%)
|
||||
AST Parsed : 29/29 (100.00%)
|
||||
Positive Passed: 28/29 (96.55%)
|
||||
Negative Passed: 17/17 (100.00%)
|
||||
Expect to Parse: tasks/coverage/misc/pass/babel-16776-m.js
|
||||
|
||||
× The keyword 'await' is reserved
|
||||
╭─[misc/pass/babel-16776-m.js:1:1]
|
||||
1 │ await /x.y/g;
|
||||
· ─────
|
||||
2 │
|
||||
╰────
|
||||
|
||||
× Unexpected token
|
||||
╭─[misc/fail/oxc-169.js:2:1]
|
||||
|
|
|
|||
|
|
@ -2,12 +2,18 @@ commit: 3bcfee23
|
|||
|
||||
semantic_babel Summary:
|
||||
AST Parsed : 2101/2101 (100.00%)
|
||||
Positive Passed: 1737/2101 (82.67%)
|
||||
Positive Passed: 1733/2101 (82.48%)
|
||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-html-comments-close/input.js
|
||||
semantic error: Unexpected token
|
||||
|
||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/3.3-function-in-if-body/input.js
|
||||
semantic error: Scope children mismatch:
|
||||
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
||||
rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2)]
|
||||
|
||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/comments/html/first-line/input.js
|
||||
semantic error: Unexpected token
|
||||
|
||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/comments/interpreter-directive/interpreter-directive-import/input.js
|
||||
semantic error: Bindings mismatch:
|
||||
after transform: ScopeId(0): ["spawn"]
|
||||
|
|
@ -38,6 +44,12 @@ semantic error: A 'return' statement can only be used within a function body.
|
|||
tasks/coverage/babel/packages/babel-parser/test/fixtures/core/uncategorised/328/input.js
|
||||
semantic error: A 'return' statement can only be used within a function body.
|
||||
|
||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/core/uncategorised/343/input.js
|
||||
semantic error: Unexpected token
|
||||
|
||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/core/uncategorised/538/input.js
|
||||
semantic error: Unexpected token
|
||||
|
||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/es2015/modules/import-declaration-trailing-comma/input.js
|
||||
semantic error: Bindings mismatch:
|
||||
after transform: ScopeId(0): ["Foo"]
|
||||
|
|
@ -769,8 +781,9 @@ semantic error: `export = <value>;` is only supported when compiling modules to
|
|||
Please consider using `export default <value>;`, or add @babel/plugin-transform-modules-commonjs to your Babel config.
|
||||
|
||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/export/equals-in-unambiguous/input.ts
|
||||
semantic error: `export = <value>;` is only supported when compiling modules to CommonJS.
|
||||
Please consider using `export default <value>;`, or add @babel/plugin-transform-modules-commonjs to your Babel config.
|
||||
semantic error: Unresolved references mismatch:
|
||||
after transform: ["f"]
|
||||
rebuilt : []
|
||||
|
||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/export/export-type/input.ts
|
||||
semantic error: Bindings mismatch:
|
||||
|
|
@ -894,8 +907,14 @@ semantic error: `import lib = require(...);` is only supported when compiling mo
|
|||
Please consider using `import lib from '...';` alongside Typescript's --allowSyntheticDefaultImports option, or add @babel/plugin-transform-modules-commonjs to your Babel config.
|
||||
|
||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/equals-require-in-unambiguous/input.ts
|
||||
semantic error: `import lib = require(...);` is only supported when compiling modules to CommonJS.
|
||||
Please consider using `import lib from '...';` alongside Typescript's --allowSyntheticDefaultImports option, or add @babel/plugin-transform-modules-commonjs to your Babel config.
|
||||
semantic error: Missing SymbolId: a
|
||||
Missing ReferenceId: require
|
||||
Binding symbols mismatch:
|
||||
after transform: ScopeId(0): [SymbolId(0)]
|
||||
rebuilt : ScopeId(0): [SymbolId(0)]
|
||||
Unresolved references mismatch:
|
||||
after transform: []
|
||||
rebuilt : ["require"]
|
||||
|
||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/export-import/input.ts
|
||||
semantic error: Missing SymbolId: A
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
semantic_misc Summary:
|
||||
AST Parsed : 27/27 (100.00%)
|
||||
Positive Passed: 16/27 (59.26%)
|
||||
AST Parsed : 29/29 (100.00%)
|
||||
Positive Passed: 17/29 (58.62%)
|
||||
tasks/coverage/misc/pass/babel-16776-m.js
|
||||
semantic error: The keyword 'await' is reserved
|
||||
|
||||
tasks/coverage/misc/pass/oxc-1288.ts
|
||||
semantic error: Bindings mismatch:
|
||||
after transform: ScopeId(0): ["from"]
|
||||
|
|
|
|||
|
|
@ -129,13 +129,16 @@ impl Case for BabelCase {
|
|||
fn new(path: PathBuf, code: String) -> Self {
|
||||
let dir = workspace_root().join(&path);
|
||||
let options = BabelOptions::from_test_path(dir.parent().unwrap());
|
||||
let source_type = SourceType::from_path(&path)
|
||||
let mut source_type = SourceType::from_path(&path)
|
||||
.unwrap()
|
||||
.with_script(true)
|
||||
.with_jsx(options.is_jsx())
|
||||
.with_typescript(options.is_typescript())
|
||||
.with_typescript_definition(options.is_typescript_definition())
|
||||
.with_module(options.is_module());
|
||||
.with_typescript_definition(options.is_typescript_definition());
|
||||
if options.is_unambiguous() {
|
||||
source_type = source_type.with_unambiguous(true);
|
||||
} else if options.is_module() {
|
||||
source_type = source_type.with_module(true);
|
||||
}
|
||||
let should_fail = Self::determine_should_fail(&path, &options);
|
||||
Self { path, code, source_type, options, should_fail, result: TestResult::ToBeRun }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
transformer_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%)
|
||||
|
|
|
|||
Loading…
Reference in a new issue