mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
refactor(transformer)!: rename TransformerOptions::react to jsx (#6888)
This commit is contained in:
parent
419343bdd5
commit
4618aa22d9
8 changed files with 20 additions and 18 deletions
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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::<JsxOptions>(value) {
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue