diff --git a/crates/oxc/src/napi/transform.rs b/crates/oxc/src/napi/transform.rs index c1c6b2925..aa2a46588 100644 --- a/crates/oxc/src/napi/transform.rs +++ b/crates/oxc/src/napi/transform.rs @@ -97,7 +97,7 @@ impl From for oxc_transformer::TransformOptions { Self { cwd: options.cwd.map(PathBuf::from).unwrap_or_default(), typescript: options.typescript.map(Into::into).unwrap_or_default(), - react: options.jsx.map(Into::into).unwrap_or_default(), + jsx: options.jsx.map(Into::into).unwrap_or_default(), es2015: options.es2015.map(Into::into).unwrap_or_default(), ..Self::default() } diff --git a/crates/oxc_transformer/src/jsx/comments.rs b/crates/oxc_transformer/src/jsx/comments.rs index 6212c7339..528cee1d0 100644 --- a/crates/oxc_transformer/src/jsx/comments.rs +++ b/crates/oxc_transformer/src/jsx/comments.rs @@ -38,14 +38,14 @@ fn update_options_with_comment( "" => { // Don't set React option unless React transform is enabled // otherwise can cause error in `ReactJsx::new` - if options.react.jsx_plugin || options.react.development { - options.react.pragma = Some(remainder.to_string()); + if options.jsx.jsx_plugin || options.jsx.development { + options.jsx.pragma = Some(remainder.to_string()); } options.typescript.jsx_pragma = Cow::from(remainder.to_string()); } // @jsxRuntime "Runtime" => { - options.react.runtime = match remainder { + options.jsx.runtime = match remainder { "classic" => JsxRuntime::Classic, "automatic" => JsxRuntime::Automatic, _ => return, @@ -53,14 +53,14 @@ fn update_options_with_comment( } // @jsxImportSource "ImportSource" => { - options.react.import_source = Some(remainder.to_string()); + options.jsx.import_source = Some(remainder.to_string()); } // @jsxFrag "Frag" => { // Don't set React option unless React transform is enabled // otherwise can cause error in `ReactJsx::new` - if options.react.jsx_plugin || options.react.development { - options.react.pragma_frag = Some(remainder.to_string()); + if options.jsx.jsx_plugin || options.jsx.development { + options.jsx.pragma_frag = Some(remainder.to_string()); } options.typescript.jsx_pragma_frag = Cow::from(remainder.to_string()); } diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index a16445370..dc70c8ecc 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -93,7 +93,7 @@ impl<'a> Transformer<'a> { let mut transformer = TransformerImpl { x0_typescript: TypeScript::new(&self.options.typescript, &self.ctx), - x1_jsx: Jsx::new(self.options.react, ast_builder, &self.ctx), + x1_jsx: Jsx::new(self.options.jsx, ast_builder, &self.ctx), x2_es2022: ES2022::new(self.options.es2022), x2_es2021: ES2021::new(self.options.es2021, &self.ctx), x2_es2020: ES2020::new(self.options.es2020, &self.ctx), diff --git a/crates/oxc_transformer/src/options/transformer.rs b/crates/oxc_transformer/src/options/transformer.rs index 3c3eca6e6..01d7cb02a 100644 --- a/crates/oxc_transformer/src/options/transformer.rs +++ b/crates/oxc_transformer/src/options/transformer.rs @@ -41,8 +41,10 @@ pub struct TransformOptions { /// [preset-typescript](https://babeljs.io/docs/babel-preset-typescript) pub typescript: TypeScriptOptions, - /// [preset-react](https://babeljs.io/docs/babel-preset-react) - pub react: JsxOptions, + /// Jsx Transform + /// + /// See [preset-react](https://babeljs.io/docs/babel-preset-react) + pub jsx: JsxOptions, pub regexp: RegExpOptions, @@ -72,7 +74,7 @@ impl TransformOptions { cwd: PathBuf::new(), assumptions: CompilerAssumptions::default(), typescript: TypeScriptOptions::default(), - react: JsxOptions { + jsx: JsxOptions { development: true, refresh: Some(ReactRefreshOptions::default()), ..JsxOptions::default() @@ -175,7 +177,7 @@ impl TransformOptions { }; let preset_name = "react"; - transformer_options.react = if let Some(value) = get_preset_options(preset_name, options) { + transformer_options.jsx = if let Some(value) = get_preset_options(preset_name, options) { match from_value::(value) { Ok(res) => res, Err(err) => { diff --git a/tasks/coverage/src/runtime/mod.rs b/tasks/coverage/src/runtime/mod.rs index cdcc49ff5..ecb02a4c9 100644 --- a/tasks/coverage/src/runtime/mod.rs +++ b/tasks/coverage/src/runtime/mod.rs @@ -162,7 +162,7 @@ impl Test262RuntimeCase { let (symbols, scopes) = SemanticBuilder::new().build(&program).semantic.into_symbol_table_and_scope_tree(); let mut options = TransformOptions::enable_all(); - options.react.refresh = None; + options.jsx.refresh = None; options.helper_loader.mode = HelperLoaderMode::External; options.typescript.only_remove_type_imports = true; Transformer::new(&allocator, self.path(), options).build_with_symbols_and_scopes( diff --git a/tasks/coverage/src/tools/semantic.rs b/tasks/coverage/src/tools/semantic.rs index 84abd3446..49bad281d 100644 --- a/tasks/coverage/src/tools/semantic.rs +++ b/tasks/coverage/src/tools/semantic.rs @@ -18,7 +18,7 @@ fn get_default_transformer_options() -> TransformOptions { TransformOptions { typescript: TypeScriptOptions::default(), es2015: ES2015Options { arrow_function: None }, - react: JsxOptions { + jsx: JsxOptions { jsx_plugin: true, jsx_self_plugin: true, jsx_source_plugin: true, @@ -150,7 +150,7 @@ impl Case for SemanticTypeScriptCase { // handle @jsx: react, `react` of behavior is match babel following options if self.base.settings.jsx.last().is_some_and(|jsx| jsx == "react") { source_type = source_type.with_module(true); - options.react.runtime = JsxRuntime::Classic; + options.jsx.runtime = JsxRuntime::Classic; } get_result(self.base.code(), source_type, self.path(), Some(options)) } diff --git a/tasks/coverage/src/tools/transformer.rs b/tasks/coverage/src/tools/transformer.rs index 6d195c731..2f1675fdc 100644 --- a/tasks/coverage/src/tools/transformer.rs +++ b/tasks/coverage/src/tools/transformer.rs @@ -50,7 +50,7 @@ fn get_default_transformer_options() -> TransformOptions { TransformOptions { typescript: TypeScriptOptions::default(), es2015: ES2015Options { arrow_function: Some(ArrowFunctionsOptions::default()) }, - react: JsxOptions { + jsx: JsxOptions { jsx_plugin: true, jsx_self_plugin: true, jsx_source_plugin: true, @@ -158,7 +158,7 @@ impl Case for TransformerTypeScriptCase { // handle @jsx: react, `react` of behavior is match babel following options if self.base.settings.jsx.last().is_some_and(|jsx| jsx == "react") { source_type = source_type.with_module(true); - options.react.runtime = JsxRuntime::Classic; + options.jsx.runtime = JsxRuntime::Classic; } get_result(self.base.code(), source_type, self.path(), Some(options)) } diff --git a/tasks/transform_conformance/src/test_case.rs b/tasks/transform_conformance/src/test_case.rs index f310f5298..83dfeb1c5 100644 --- a/tasks/transform_conformance/src/test_case.rs +++ b/tasks/transform_conformance/src/test_case.rs @@ -113,7 +113,7 @@ pub trait TestCase { if b { // Skip deprecated react options if self.transform_options().as_ref().is_ok_and(|options| { - options.react.use_built_ins.is_some() || options.react.use_spread.is_some() + options.jsx.use_built_ins.is_some() || options.jsx.use_spread.is_some() }) { return true; }