diff --git a/crates/oxc_transformer/src/context.rs b/crates/oxc_transformer/src/context.rs index 9b0596f4ad57a4..1dce7a44d32fcd 100644 --- a/crates/oxc_transformer/src/context.rs +++ b/crates/oxc_transformer/src/context.rs @@ -37,6 +37,7 @@ impl<'a> TransformCtx<'a> { } /// Add an Error + #[allow(unused)] pub fn error>(&self, error: T) { self.errors.borrow_mut().push(error.into()); } diff --git a/crates/oxc_transformer/src/decorators/mod.rs b/crates/oxc_transformer/src/decorators/mod.rs index 5e997baf69fa92..1da046703ec821 100644 --- a/crates/oxc_transformer/src/decorators/mod.rs +++ b/crates/oxc_transformer/src/decorators/mod.rs @@ -26,5 +26,5 @@ impl<'a> Decorators<'a> { // Transformers impl<'a> Decorators<'a> { - pub fn transform_statement(&mut self, _stmt: &mut Statement<'_>) {} + pub fn transform_statement(&self, _stmt: &mut Statement<'_>) {} } diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index 827f0afd126dac..adfa1151cd8866 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -10,6 +10,7 @@ // Core mod compiler_assumptions; mod context; +mod options; // Presets: mod decorators; mod react; @@ -26,34 +27,17 @@ use oxc_diagnostics::Error; use oxc_semantic::Semantic; pub use crate::{ - compiler_assumptions::CompilerAssumptions, - decorators::{Decorators, DecoratorsOptions}, - react::{React, ReactDisplayName, ReactJsx, ReactJsxSelf, ReactJsxSource, ReactOptions}, - typescript::{TypeScript, TypeScriptOptions}, + compiler_assumptions::CompilerAssumptions, decorators::DecoratorsOptions, + options::TransformOptions, react::ReactOptions, typescript::TypeScriptOptions, }; -use crate::context::{Ctx, TransformCtx}; - -#[allow(unused)] -#[derive(Debug, Default, Clone)] -pub struct TransformOptions { - // Core - /// Set assumptions in order to produce smaller output. - /// For more information, check the [assumptions](https://babel.dev/docs/assumptions) documentation page. - pub assumptions: CompilerAssumptions, - - // Plugins - /// [proposal-decorators](https://babeljs.io/docs/babel-plugin-proposal-decorators) - pub decorators: DecoratorsOptions, - - /// [preset-typescript](https://babeljs.io/docs/babel-preset-typescript) - pub typescript: TypeScriptOptions, - - /// [preset-react](https://babeljs.io/docs/babel-preset-react) - pub react: ReactOptions, -} +use crate::{ + context::{Ctx, TransformCtx}, + decorators::Decorators, + react::React, + typescript::TypeScript, +}; -#[allow(unused)] pub struct Transformer<'a> { ctx: Ctx<'a>, // NOTE: all callbacks must run in order. diff --git a/crates/oxc_transformer/src/options.rs b/crates/oxc_transformer/src/options.rs new file mode 100644 index 00000000000000..baba01f969a44b --- /dev/null +++ b/crates/oxc_transformer/src/options.rs @@ -0,0 +1,22 @@ +use crate::{ + compiler_assumptions::CompilerAssumptions, decorators::DecoratorsOptions, react::ReactOptions, + typescript::TypeScriptOptions, +}; + +#[derive(Debug, Default, Clone)] +pub struct TransformOptions { + // Core + /// Set assumptions in order to produce smaller output. + /// For more information, check the [assumptions](https://babel.dev/docs/assumptions) documentation page. + pub assumptions: CompilerAssumptions, + + // Plugins + /// [proposal-decorators](https://babeljs.io/docs/babel-plugin-proposal-decorators) + pub decorators: DecoratorsOptions, + + /// [preset-typescript](https://babeljs.io/docs/babel-preset-typescript) + pub typescript: TypeScriptOptions, + + /// [preset-react](https://babeljs.io/docs/babel-preset-react) + pub react: ReactOptions, +} diff --git a/crates/oxc_transformer/src/react/display_name/mod.rs b/crates/oxc_transformer/src/react/display_name/mod.rs index d5ce654c7cf555..57b9ba0c63e398 100644 --- a/crates/oxc_transformer/src/react/display_name/mod.rs +++ b/crates/oxc_transformer/src/react/display_name/mod.rs @@ -54,7 +54,7 @@ impl<'a> ReactDisplayName<'a> { } /// `let foo = React.createClass({})` - pub fn transform_variable_declarator(&mut self, declarator: &mut VariableDeclarator<'a>) { + pub fn transform_variable_declarator(&self, declarator: &mut VariableDeclarator<'a>) { let Some(init_expr) = declarator.init.as_mut() else { return }; let Some(obj_expr) = Self::get_object_from_create_class(init_expr) else { return; @@ -67,7 +67,7 @@ impl<'a> ReactDisplayName<'a> { } /// `{foo: React.createClass({})}` - pub fn transform_object_property(&mut self, prop: &mut ObjectProperty<'a>) { + pub fn transform_object_property(&self, prop: &mut ObjectProperty<'a>) { let Some(obj_expr) = Self::get_object_from_create_class(&mut prop.value) else { return }; let Some(name) = prop.key.static_name() else { return }; let name = self.ctx.ast.new_atom(&name); @@ -76,10 +76,7 @@ impl<'a> ReactDisplayName<'a> { /// `export default React.createClass({})` /// Uses the current file name as the display name. - pub fn transform_export_default_declaration( - &mut self, - decl: &mut ExportDefaultDeclaration<'a>, - ) { + pub fn transform_export_default_declaration(&self, decl: &mut ExportDefaultDeclaration<'a>) { let ExportDefaultDeclarationKind::Expression(expr) = &mut decl.declaration else { return }; let Some(obj_expr) = Self::get_object_from_create_class(expr) else { return }; let name = self.ctx.ast.new_atom(self.ctx.filename()); diff --git a/crates/oxc_transformer/src/react/mod.rs b/crates/oxc_transformer/src/react/mod.rs index 401c18622a071f..b8575aef24f490 100644 --- a/crates/oxc_transformer/src/react/mod.rs +++ b/crates/oxc_transformer/src/react/mod.rs @@ -50,7 +50,7 @@ impl<'a> React<'a> { // Transforms impl<'a> React<'a> { - pub fn transform_expression(&mut self, expr: &mut Expression<'a>) { + pub fn transform_expression(&self, expr: &mut Expression<'a>) { match expr { Expression::AssignmentExpression(e) => { self.display_name.transform_assignment_expression(e); @@ -65,18 +65,15 @@ impl<'a> React<'a> { } } - pub fn transform_variable_declarator(&mut self, declarator: &mut VariableDeclarator<'a>) { + pub fn transform_variable_declarator(&self, declarator: &mut VariableDeclarator<'a>) { self.display_name.transform_variable_declarator(declarator); } - pub fn transform_object_property(&mut self, prop: &mut ObjectProperty<'a>) { + pub fn transform_object_property(&self, prop: &mut ObjectProperty<'a>) { self.display_name.transform_object_property(prop); } - pub fn transform_export_default_declaration( - &mut self, - decl: &mut ExportDefaultDeclaration<'a>, - ) { + pub fn transform_export_default_declaration(&self, decl: &mut ExportDefaultDeclaration<'a>) { self.display_name.transform_export_default_declaration(decl); } diff --git a/tasks/transform_conformance/src/lib.rs b/tasks/transform_conformance/src/lib.rs index a179f549cfb31f..315f843da7c2e4 100644 --- a/tasks/transform_conformance/src/lib.rs +++ b/tasks/transform_conformance/src/lib.rs @@ -165,28 +165,23 @@ impl TestRunner { return None; } } - if EXCLUDE_TESTS.iter().any(|p| path.to_string_lossy().contains(p)) { return None; } - - let test_case = TestCaseKind::from_path(path); - if let Some(test_case) = test_case { - if test_case.skip_test_case() { - return None; - } - - return Some(test_case); - } - None + TestCaseKind::from_path(path) + .filter(|test_case| !test_case.skip_test_case()) }) .partition(|p| matches!(p, TestCaseKind::Transform(_))); transform_paths.sort_unstable_by(|a, b| a.path().cmp(b.path())); exec_paths.sort_unstable_by(|a, b| a.path().cmp(b.path())); - transform_files.insert((*case).to_string(), transform_paths); - exec_files.insert((*case).to_string(), exec_paths); + if !transform_paths.is_empty() { + transform_files.insert((*case).to_string(), transform_paths); + } + if !exec_paths.is_empty() { + exec_files.insert((*case).to_string(), exec_paths); + } } (transform_files, exec_files) @@ -200,11 +195,6 @@ impl TestRunner { let mut all_passed_count = 0; for (case, test_cases) in paths { - // Skip empty test cases, e.g. some cases do not have `exec.js` file. - if test_cases.is_empty() { - continue; - } - let case_root = root.join(&case).join("test/fixtures"); let num_of_tests = test_cases.len(); total += num_of_tests;