Skip to content

Commit

Permalink
fix(transformer): turn on react preset by default (#2968)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored Apr 14, 2024
1 parent d575261 commit 10814d5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
48 changes: 29 additions & 19 deletions crates/oxc_transformer/src/react/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@ use std::borrow::Cow;

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)]
#[serde(rename_all = "camelCase")]
pub struct ReactOptions {
Expand Down Expand Up @@ -68,10 +86,10 @@ pub struct ReactOptions {
impl Default for ReactOptions {
fn default() -> Self {
Self {
jsx_plugin: false,
display_name_plugin: false,
jsx_self_plugin: false,
jsx_source_plugin: false,
jsx_plugin: true,
display_name_plugin: true,
jsx_self_plugin: true,
jsx_source_plugin: true,
runtime: ReactJsxRuntime::default(),
development: default_as_true(),
pure: default_as_true(),
Expand All @@ -82,22 +100,14 @@ impl Default for ReactOptions {
}
}

#[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")
}
impl ReactOptions {
pub fn is_jsx_self_plugin_enabled(&self) -> bool {
self.jsx_self_plugin && self.development
}

fn default_for_pragma_frag() -> Cow<'static, str> {
Cow::Borrowed("React.Fragment")
pub fn is_jsx_source_plugin_enabled(&self) -> bool {
self.jsx_source_plugin && self.development
}
}

/// Decides which runtime to use.
Expand Down
22 changes: 6 additions & 16 deletions tasks/transform_conformance/src/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,11 @@ pub trait TestCase {

let react = options.get_preset("react").map_or_else(
|| {
let mut react_options = options
.get_plugin("transform-react-jsx")
.map(|options| {
let mut options = get_options::<ReactOptions>(options);
options.jsx_plugin = true;
options
})
.unwrap_or_default();
let jsx_plugin = options.get_plugin("transform-react-jsx");
let has_jsx_plugin = jsx_plugin.as_ref().is_some();
let mut react_options =
jsx_plugin.map(get_options::<ReactOptions>).unwrap_or_default();
react_options.jsx_plugin = has_jsx_plugin;
react_options.display_name_plugin =
options.get_plugin("transform-react-display-name").is_some();
react_options.jsx_self_plugin =
Expand All @@ -105,14 +102,7 @@ pub trait TestCase {
options.get_plugin("transform-react-jsx-source").is_some();
react_options
},
|options| {
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
},
get_options::<ReactOptions>,
);

TransformOptions {
Expand Down

0 comments on commit 10814d5

Please sign in to comment.