Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(span): treat .js as module file (reverts the previous breaking change) #5612

Merged
merged 1 commit into from
Sep 8, 2024
Merged
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
9 changes: 4 additions & 5 deletions crates/oxc_span/src/source_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,7 @@ impl SourceType {
})?;

let (language, module_kind) = match extension {
"js" => (Language::JavaScript, ModuleKind::Unambiguous),
"mjs" | "jsx" => (Language::JavaScript, ModuleKind::Module),
"js" | "mjs" | "jsx" => (Language::JavaScript, ModuleKind::Module),
"cjs" => (Language::JavaScript, ModuleKind::Script),
"ts" if file_name.ends_with(".d.ts") => {
(Language::TypeScriptDefinition, ModuleKind::Module)
Expand Down Expand Up @@ -508,15 +507,15 @@ mod tests {
assert!(!ty.is_typescript(), "{ty:?}");
}

assert_eq!(SourceType::jsx().with_unambiguous(true), js);
assert_eq!(SourceType::jsx(), js);
assert_eq!(SourceType::jsx().with_module(true), jsx);

assert!(js.is_unambiguous());
assert!(js.is_module());
assert!(mjs.is_module());
assert!(cjs.is_script());
assert!(jsx.is_module());

assert!(!js.is_strict());
assert!(js.is_strict());
assert!(mjs.is_strict());
assert!(!cjs.is_strict());
assert!(jsx.is_strict());
Expand Down
62 changes: 22 additions & 40 deletions tasks/coverage/parser_babel.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
commit: 3bcfee23

parser_babel Summary:
AST Parsed : 2089/2101 (99.43%)
Positive Passed: 2079/2101 (98.95%)
Negative Passed: 1381/1493 (92.50%)
AST Parsed : 2093/2101 (99.62%)
Positive Passed: 2083/2101 (99.14%)
Negative Passed: 1382/1493 (92.57%)
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
Expand All @@ -27,7 +27,6 @@ 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
Expand Down Expand Up @@ -116,20 +115,6 @@ 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
Expand All @@ -147,22 +132,6 @@ 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`
Expand Down Expand Up @@ -5057,6 +5026,12 @@ 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 }
Expand Down Expand Up @@ -5558,6 +5533,13 @@ 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;
Expand Down Expand Up @@ -7372,10 +7354,10 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
· ───────────
╰────

× The keyword 'await' is reserved
╭─[babel/packages/babel-parser/test/fixtures/esprima/es2015-identifier/invalid_expression_await/input.js:1:21]
× Cannot use export statement outside a module
╭─[babel/packages/babel-parser/test/fixtures/esprima/es2015-identifier/invalid_expression_await/input.js:1:1]
1 │ export var answer = await + 1;
· ─────
· ─────
╰────

× Invalid Character `🀒`
Expand All @@ -7397,10 +7379,10 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
╰────
help: Try insert a semicolon here

× The keyword 'await' is reserved
╭─[babel/packages/babel-parser/test/fixtures/esprima/es2015-identifier/invalid_var_await/input.js:1:12]
× Cannot use export statement outside a module
╭─[babel/packages/babel-parser/test/fixtures/esprima/es2015-identifier/invalid_var_await/input.js:1:1]
1 │ export var await;
· ─────
· ─────
╰────

× Expected `from` but found `default`
Expand Down
10 changes: 1 addition & 9 deletions tasks/coverage/parser_misc.snap
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
parser_misc Summary:
AST Parsed : 29/29 (100.00%)
Positive Passed: 28/29 (96.55%)
Positive Passed: 29/29 (100.00%)
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]
Expand Down
14 changes: 1 addition & 13 deletions tasks/coverage/semantic_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@ commit: 3bcfee23

semantic_babel Summary:
AST Parsed : 2101/2101 (100.00%)
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

Positive Passed: 1737/2101 (82.67%)
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"]
Expand Down Expand Up @@ -44,12 +38,6 @@ 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"]
Expand Down
4 changes: 3 additions & 1 deletion tasks/coverage/semantic_misc.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ semantic_misc Summary:
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
semantic error: Symbol flags mismatch:
after transform: SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable)

tasks/coverage/misc/pass/oxc-1288.ts
semantic error: Bindings mismatch:
Expand Down
1 change: 1 addition & 0 deletions tasks/coverage/src/babel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl Case for BabelCase {
let options = BabelOptions::from_test_path(dir.parent().unwrap());
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());
Expand Down
Loading