diff --git a/src/transpiling/jsx_precompile.rs b/src/transpiling/jsx_precompile.rs index bc2b969..32b0c35 100644 --- a/src/transpiling/jsx_precompile.rs +++ b/src/transpiling/jsx_precompile.rs @@ -14,10 +14,6 @@ pub struct JsxPrecompile { // The import path to import the jsx runtime from. Will be // `/jsx-runtime`. import_source: String, - // Optionally, skip serializing children to string for the - // components in this list. These typically rely on React.Children - // API or need the actual virtual JSX nodes for other reasons. - skip_child_serialization: Option>, // Internal state next_index: usize, @@ -43,21 +39,15 @@ impl Default for JsxPrecompile { import_jsx: None, import_jsx_ssr: None, import_jsx_attr: None, - skip_child_serialization: None, } } } impl JsxPrecompile { - pub fn new( - import_source: String, - development: bool, - skip_child_serialization: Option>, - ) -> Self { + pub fn new(import_source: String, development: bool) -> Self { Self { import_source, development, - skip_child_serialization, ..JsxPrecompile::default() } } @@ -346,7 +336,6 @@ impl JsxPrecompile { fn serialize_jsx_children_to_expr( &mut self, children: &Vec, - parent_tag_name: Option<&str>, ) -> Option { // Add children as a "children" prop. match children.len() { @@ -368,20 +357,11 @@ impl JsxPrecompile { } // Case:
JSXElementChild::JSXElement(jsx_element) => { - if let Some(allowed_elems) = &self.skip_child_serialization { - if let Some(parent_name) = parent_tag_name { - if allowed_elems.iter().any(|e| e == parent_name) { - return Some(Expr::Call( - self.serialize_jsx_to_call_expr(jsx_element), - )); - } - } - } Some(self.serialize_jsx(jsx_element)) } // Case:
<>
JSXElementChild::JSXFragment(jsx_frag) => { - self.serialize_jsx_children_to_expr(&jsx_frag.children, None) + self.serialize_jsx_children_to_expr(&jsx_frag.children) } // Invalid, was part of an earlier JSX iteration, but no // transform supports it. Babel and TypeScript error when they @@ -426,7 +406,7 @@ impl JsxPrecompile { // Case:
<>
JSXElementChild::JSXFragment(jsx_frag) => { if let Some(child_expr) = - self.serialize_jsx_children_to_expr(&jsx_frag.children, None) + self.serialize_jsx_children_to_expr(&jsx_frag.children) { match child_expr { Expr::Array(array_lit) => { @@ -489,11 +469,6 @@ impl JsxPrecompile { } }; - let name_str: Option = match &name_expr { - Expr::Ident(ident) => Some(ident.sym.to_string()), - _ => None, - }; - let mut args: Vec = vec![]; args.push(ExprOrSpread { spread: None, @@ -588,8 +563,7 @@ impl JsxPrecompile { } // Add children as a "children" prop. - let child_expr = - self.serialize_jsx_children_to_expr(&el.children, name_str.as_deref()); + let child_expr = self.serialize_jsx_children_to_expr(&el.children); if let Some(expr) = child_expr { let children_name = PropName::Ident(quote_ident!("children")); @@ -1044,7 +1018,7 @@ impl VisitMut for JsxPrecompile { // Case: <><> JSXElementChild::JSXFragment(jsx_frag) => { let serialized = - self.serialize_jsx_children_to_expr(&jsx_frag.children, None); + self.serialize_jsx_children_to_expr(&jsx_frag.children); if let Some(serialized_expr) = serialized { *expr = serialized_expr } @@ -1732,11 +1706,7 @@ const a = _jsx(a.b.c.d, { #[test] fn import_source_option_test() { test_transform( - JsxPrecompile::new( - "foobar".to_string(), - false, - Some(vec!["Head".to_string()]), - ), + JsxPrecompile::new("foobar".to_string(), false), r#"const a =
foo
;"#, r#"import { jsxssr as _jsxssr } from "foobar/jsx-runtime"; const $$_tpl_1 = [ @@ -1746,28 +1716,10 @@ const a = _jsxssr($$_tpl_1);"#, ); } - #[test] - fn skip_component_child_serialization_option_test() { - test_transform( - JsxPrecompile::new( - "react".to_string(), - false, - Some(vec!["Head".to_string()]), - ), - r#"const a = foo;"#, - r#"import { jsx as _jsx } from "react/jsx-runtime"; -const a = _jsx(Head, { - children: _jsx("title", { - children: "foo" - }) -});"#, - ); - } - #[test] fn development_option_test() { test_transform( - JsxPrecompile::new("react".to_string(), true, None), + JsxPrecompile::new("react".to_string(), true), r#"const a = foo;"#, r#"import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime"; const a = _jsxDEV(Foo, { diff --git a/src/transpiling/mod.rs b/src/transpiling/mod.rs index a29a905..24adb97 100644 --- a/src/transpiling/mod.rs +++ b/src/transpiling/mod.rs @@ -314,7 +314,6 @@ pub fn fold_program( as_folder(jsx_precompile::JsxPrecompile::new( options.jsx_import_source.clone().unwrap_or_default(), options.jsx_development, - None )), options.jsx_import_source.is_some() && !options.transform_jsx