From d411258be4ae4b31d243c1702604b31c2567384a Mon Sep 17 00:00:00 2001 From: Boshen Date: Sat, 28 Oct 2023 16:46:33 +0800 Subject: [PATCH] feat(transformer): finish transform jsx attribute value (#1078) --- crates/oxc_transformer/src/react_jsx/mod.rs | 24 ++++++++++----------- tasks/transform_conformance/babel.snap.md | 6 ++---- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/crates/oxc_transformer/src/react_jsx/mod.rs b/crates/oxc_transformer/src/react_jsx/mod.rs index 44b9c1105..a7961f9c0 100644 --- a/crates/oxc_transformer/src/react_jsx/mod.rs +++ b/crates/oxc_transformer/src/react_jsx/mod.rs @@ -353,27 +353,25 @@ impl<'a> ReactJsx<'a> { } fn transform_jsx_attribute_value( - &self, + &mut self, value: Option<&JSXAttributeValue<'a>>, ) -> Option> { match value { Some(JSXAttributeValue::StringLiteral(s)) => { Some(self.ast.literal_string_expression(s.clone())) } - Some(JSXAttributeValue::Element(_) | JSXAttributeValue::Fragment(_)) => { - /* TODO */ - None + Some(JSXAttributeValue::Element(e)) => { + self.transform_jsx(&JSXElementOrFragment::Element(e)) } - Some(JSXAttributeValue::ExpressionContainer(c)) => { - match &c.expression { - JSXExpression::Expression(e) => Some(self.ast.copy(e)), - JSXExpression::EmptyExpression(_e) => - /* TODO */ - { - None - } + Some(JSXAttributeValue::Fragment(e)) => { + self.transform_jsx(&JSXElementOrFragment::Fragment(e)) + } + Some(JSXAttributeValue::ExpressionContainer(c)) => match &c.expression { + JSXExpression::Expression(e) => Some(self.ast.copy(e)), + JSXExpression::EmptyExpression(_e) => { + Some(self.ast.literal_boolean_expression(BooleanLiteral::new(SPAN, true))) } - } + }, None => Some(self.ast.literal_boolean_expression(BooleanLiteral::new(SPAN, true))), } } diff --git a/tasks/transform_conformance/babel.snap.md b/tasks/transform_conformance/babel.snap.md index aaed48238..4047d4619 100644 --- a/tasks/transform_conformance/babel.snap.md +++ b/tasks/transform_conformance/babel.snap.md @@ -1,4 +1,4 @@ -Passed: 215/1083 +Passed: 217/1083 # All Passed: * babel-plugin-transform-numeric-separator @@ -804,7 +804,7 @@ Passed: 215/1083 * regression/11061/input.mjs * variable-declaration/non-null-in-optional-chain/input.ts -# babel-plugin-transform-react-jsx (66/172) +# babel-plugin-transform-react-jsx (68/172) * autoImport/after-polyfills/input.mjs * autoImport/after-polyfills-2/input.mjs * autoImport/after-polyfills-compiled-to-cjs/input.mjs @@ -846,7 +846,6 @@ Passed: 215/1083 * react/optimisation.react.constant-elements/input.js * react/pragma-works-with-no-space-at-the-end/input.js * react/should-add-quotes-es3/input.js -* react/should-allow-elements-as-attributes/input.js * react/should-allow-jsx-docs-comment-with-pragma/input.js * react/should-allow-no-pragmafrag-if-frag-unused/input.js * react/should-allow-pragmafrag-and-frag/input.js @@ -878,7 +877,6 @@ Passed: 215/1083 * react-automatic/optimisation.react.constant-elements/input.js * react-automatic/pragma-works-with-no-space-at-the-end/input.js * react-automatic/should-add-quotes-es3/input.js -* react-automatic/should-allow-elements-as-attributes/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-valueless-key/input.js