mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
fix(transformer): turn on react preset by default (#2968)
This commit is contained in:
parent
d57526103c
commit
10814d5331
2 changed files with 35 additions and 35 deletions
|
|
@ -2,6 +2,24 @@ use std::borrow::Cow;
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn default_as_true() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn default_for_import_source() -> Cow<'static, str> {
|
||||||
|
Cow::Borrowed("react")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_for_pragma() -> Cow<'static, str> {
|
||||||
|
Cow::Borrowed("React.createElement")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_for_pragma_frag() -> Cow<'static, str> {
|
||||||
|
Cow::Borrowed("React.Fragment")
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct ReactOptions {
|
pub struct ReactOptions {
|
||||||
|
|
@ -68,10 +86,10 @@ pub struct ReactOptions {
|
||||||
impl Default for ReactOptions {
|
impl Default for ReactOptions {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
jsx_plugin: false,
|
jsx_plugin: true,
|
||||||
display_name_plugin: false,
|
display_name_plugin: true,
|
||||||
jsx_self_plugin: false,
|
jsx_self_plugin: true,
|
||||||
jsx_source_plugin: false,
|
jsx_source_plugin: true,
|
||||||
runtime: ReactJsxRuntime::default(),
|
runtime: ReactJsxRuntime::default(),
|
||||||
development: default_as_true(),
|
development: default_as_true(),
|
||||||
pure: default_as_true(),
|
pure: default_as_true(),
|
||||||
|
|
@ -82,22 +100,14 @@ impl Default for ReactOptions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
impl ReactOptions {
|
||||||
fn default_as_true() -> bool {
|
pub fn is_jsx_self_plugin_enabled(&self) -> bool {
|
||||||
true
|
self.jsx_self_plugin && self.development
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
pub fn is_jsx_source_plugin_enabled(&self) -> bool {
|
||||||
fn default_for_import_source() -> Cow<'static, str> {
|
self.jsx_source_plugin && self.development
|
||||||
Cow::Borrowed("react")
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn default_for_pragma() -> Cow<'static, str> {
|
|
||||||
Cow::Borrowed("React.createElement")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn default_for_pragma_frag() -> Cow<'static, str> {
|
|
||||||
Cow::Borrowed("React.Fragment")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decides which runtime to use.
|
/// Decides which runtime to use.
|
||||||
|
|
|
||||||
|
|
@ -89,14 +89,11 @@ pub trait TestCase {
|
||||||
|
|
||||||
let react = options.get_preset("react").map_or_else(
|
let react = options.get_preset("react").map_or_else(
|
||||||
|| {
|
|| {
|
||||||
let mut react_options = options
|
let jsx_plugin = options.get_plugin("transform-react-jsx");
|
||||||
.get_plugin("transform-react-jsx")
|
let has_jsx_plugin = jsx_plugin.as_ref().is_some();
|
||||||
.map(|options| {
|
let mut react_options =
|
||||||
let mut options = get_options::<ReactOptions>(options);
|
jsx_plugin.map(get_options::<ReactOptions>).unwrap_or_default();
|
||||||
options.jsx_plugin = true;
|
react_options.jsx_plugin = has_jsx_plugin;
|
||||||
options
|
|
||||||
})
|
|
||||||
.unwrap_or_default();
|
|
||||||
react_options.display_name_plugin =
|
react_options.display_name_plugin =
|
||||||
options.get_plugin("transform-react-display-name").is_some();
|
options.get_plugin("transform-react-display-name").is_some();
|
||||||
react_options.jsx_self_plugin =
|
react_options.jsx_self_plugin =
|
||||||
|
|
@ -105,14 +102,7 @@ pub trait TestCase {
|
||||||
options.get_plugin("transform-react-jsx-source").is_some();
|
options.get_plugin("transform-react-jsx-source").is_some();
|
||||||
react_options
|
react_options
|
||||||
},
|
},
|
||||||
|options| {
|
get_options::<ReactOptions>,
|
||||||
let mut react_options = get_options::<ReactOptions>(options);
|
|
||||||
react_options.jsx_plugin = true;
|
|
||||||
react_options.jsx_self_plugin = true;
|
|
||||||
react_options.jsx_source_plugin = true;
|
|
||||||
react_options.display_name_plugin = true;
|
|
||||||
react_options
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
TransformOptions {
|
TransformOptions {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue