Skip to content

Commit

Permalink
refactor(transformer)!: rename TransformerOptions::react to jsx (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Oct 25, 2024
1 parent 419343b commit 4618aa2
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion crates/oxc/src/napi/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl From<TransformOptions> 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()
}
Expand Down
12 changes: 6 additions & 6 deletions crates/oxc_transformer/src/jsx/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,29 @@ 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,
};
}
// @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());
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
10 changes: 6 additions & 4 deletions crates/oxc_transformer/src/options/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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::<JsxOptions>(value) {
Ok(res) => res,
Err(err) => {
Expand Down
2 changes: 1 addition & 1 deletion tasks/coverage/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions tasks/coverage/src/tools/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
}
Expand Down
4 changes: 2 additions & 2 deletions tasks/coverage/src/tools/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion tasks/transform_conformance/src/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 4618aa2

Please sign in to comment.