Skip to content
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
17 changes: 14 additions & 3 deletions crates/oxc_transformer/src/options/babel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,39 @@ fn default_as_true() -> bool {

impl BabelOptions {
/// Read options.json and merge them with options.json from ancestors directories.
///
/// Babel's fixture hierarchy: task → suite → category.
/// Suite options.json REPLACES category plugins (not merge).
///
/// # Panics
pub fn from_test_path(path: &Path) -> Self {
let mut babel_options: Option<Self> = None;
let mut plugins_json = None;
let mut presets_json = None;
// Track if suite level (level 1) has options.json - if so, skip category plugins
let mut suite_has_options = false;

for path in path.ancestors().take(3) {
for (level, path) in path.ancestors().take(3).enumerate() {
let file = path.join("options.json");
if !file.exists() {
continue;
}

if level == 1 {
suite_has_options = true;
}

let content = std::fs::read_to_string(&file).unwrap();
let mut new_value = serde_json::from_str::<serde_json::Value>(&content).unwrap();

let new_plugins = new_value.as_object_mut().unwrap().remove("plugins");
if plugins_json.is_none() {
// Skip category (level 2) plugins if suite (level 1) has options.json
if plugins_json.is_none() && !(level == 2 && suite_has_options) {
plugins_json = new_plugins;
}

let new_presets = new_value.as_object_mut().unwrap().remove("presets");
if presets_json.is_none() {
if presets_json.is_none() && !(level == 2 && suite_has_options) {
presets_json = new_presets;
}

Expand Down
27 changes: 20 additions & 7 deletions tasks/coverage/snapshots/parser_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ commit: 92c052dc
parser_babel Summary:
AST Parsed : 2224/2224 (100.00%)
Positive Passed: 2211/2224 (99.42%)
Negative Passed: 1665/1689 (98.58%)
Negative Passed: 1668/1689 (98.76%)
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2026/explicit-resource-management/invalid-for-using-of-no-initializer/input.js

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/cast/unparenthesized-assert-and-assign/input.ts
Expand Down Expand Up @@ -34,12 +34,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/dts/invalid-class-initializer/input.ts

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/expect-plugin/export-interface/input.js

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/expect-plugin/export-type/input.js

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/expect-plugin/export-type-named/input.js

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/export/equals-in-script/input.ts

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/equals-in-script/input.ts
Expand Down Expand Up @@ -13208,6 +13202,25 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
╰────
help: Try inserting a semicolon here

× Unexpected token
╭─[babel/packages/babel-parser/test/fixtures/typescript/expect-plugin/export-interface/input.js:1:8]
1 │ export interface Foo {}
· ─────────
╰────

× Unexpected token
╭─[babel/packages/babel-parser/test/fixtures/typescript/expect-plugin/export-type/input.js:1:8]
1 │ export type Foo = number;
· ────
╰────

× Unexpected token
╭─[babel/packages/babel-parser/test/fixtures/typescript/expect-plugin/export-type-named/input.js:2:8]
1 │ var Foo;
2 │ export type { Foo };
· ────
╰────

× Unexpected exponentiation expression
╭─[babel/packages/babel-parser/test/fixtures/typescript/exponentiation/await-non-null-before-exponential/input.ts:1:14]
1 │ async (a) => await a! ** 6;
Expand Down
Loading