diff --git a/crates/oxc_transformer/src/react_jsx/mod.rs b/crates/oxc_transformer/src/react_jsx/mod.rs index a3b77266d..9ab7e8180 100644 --- a/crates/oxc_transformer/src/react_jsx/mod.rs +++ b/crates/oxc_transformer/src/react_jsx/mod.rs @@ -316,23 +316,28 @@ impl<'a> ReactJsx<'a> { let children = e.children(); // Append children to object properties in automatic mode - if is_automatic && !children.is_empty() { - let ident = IdentifierName::new(SPAN, "children".into()); - let key = self.ast.property_key_identifier(ident); - let value = if children.len() == 1 { - self.transform_jsx_child(&children[0]) - } else { - let mut elements = self.ast.new_vec_with_capacity(children.len()); - for child in children { - if let Some(e) = self.transform_jsx_child(child) { - elements.push(ArrayExpressionElement::Expression(e)); - } - } - need_jsxs = true; - Some(self.ast.array_expression(SPAN, elements, None)) - }; - if let Some(value) = value { + if is_automatic { + let allocator = self.ast.allocator; + let mut children = Vec::from_iter_in( + children.iter().filter_map(|child| self.transform_jsx_child(child)), + allocator, + ); + let children_len = children.len(); + if children_len != 0 { + let value = if children_len == 1 { + children.pop().unwrap() + } else { + let elements = Vec::from_iter_in( + children.into_iter().map(ArrayExpressionElement::Expression), + allocator, + ); + need_jsxs = true; + self.ast.array_expression(SPAN, elements, None) + }; + let kind = PropertyKind::Init; + let ident = IdentifierName::new(SPAN, "children".into()); + let key = self.ast.property_key_identifier(ident); let object_property = self.ast.object_property(SPAN, kind, key, value, None, false, false, false); properties.push(ObjectPropertyKind::ObjectProperty(object_property)); diff --git a/tasks/transform_conformance/babel.snap.md b/tasks/transform_conformance/babel.snap.md index 99611dddb..ad833e72e 100644 --- a/tasks/transform_conformance/babel.snap.md +++ b/tasks/transform_conformance/babel.snap.md @@ -1,4 +1,4 @@ -Passed: 278/1113 +Passed: 283/1113 # All Passed: * babel-plugin-transform-numeric-separator @@ -825,9 +825,8 @@ Passed: 278/1113 * regression/11061/input.mjs * variable-declaration/non-null-in-optional-chain/input.ts -# babel-plugin-transform-react-jsx (116/170) +# babel-plugin-transform-react-jsx (121/170) * autoImport/after-polyfills-compiled-to-cjs/input.mjs -* autoImport/auto-import-react-source-type-module/input.js * autoImport/auto-import-react-source-type-script/input.js * autoImport/complicated-scope-module/input.js * pure/false-pragma-comment-automatic-runtime/input.js @@ -855,17 +854,13 @@ Passed: 278/1113 * react/wraps-props-in-react-spread-for-last-spread-attributes-babel-7/input.js * react/wraps-props-in-react-spread-for-middle-spread-attributes-babel-7/input.js * react-automatic/arrow-functions/input.js -* react-automatic/does-not-add-source-self-automatic/input.mjs -* react-automatic/handle-nonstatic-children/input.js * react-automatic/optimisation.react.constant-elements/input.js * react-automatic/should-add-quotes-es3/input.js * react-automatic/should-allow-nested-fragments/input.js -* react-automatic/should-avoid-wrapping-in-extra-parens-if-not-needed/input.js * react-automatic/should-disallow-spread-children/input.js * react-automatic/should-disallow-valueless-key/input.js * react-automatic/should-disallow-xml-namespacing/input.js * react-automatic/should-handle-attributed-elements/input.js -* react-automatic/should-properly-handle-comments-between-props/input.js * react-automatic/should-throw-error-namespaces-if-not-flag/input.js * react-automatic/should-throw-when-filter-is-specified/input.js * react-automatic/should-warn-when-pragma-or-pragmaFrag-is-set/input.js