feat(transformer): finish transform jsx attribute value (#1078)

This commit is contained in:
Boshen 2023-10-28 16:46:33 +08:00 committed by GitHub
parent 5fb27fbe8a
commit d411258be4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 17 deletions

View file

@ -353,27 +353,25 @@ impl<'a> ReactJsx<'a> {
}
fn transform_jsx_attribute_value(
&self,
&mut self,
value: Option<&JSXAttributeValue<'a>>,
) -> Option<Expression<'a>> {
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))),
}
}

View file

@ -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