mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
feat(transformer): add props null to React.createElement (#1074)
This commit is contained in:
parent
0a0e93b55d
commit
d6ba8910ba
3 changed files with 10 additions and 13 deletions
|
|
@ -30,8 +30,10 @@ enum JSXElementOrFragment<'a, 'b> {
|
||||||
impl<'a, 'b> JSXElementOrFragment<'a, 'b> {
|
impl<'a, 'b> JSXElementOrFragment<'a, 'b> {
|
||||||
fn attributes(&self) -> Option<&'b Vec<'a, JSXAttributeItem<'a>>> {
|
fn attributes(&self) -> Option<&'b Vec<'a, JSXAttributeItem<'a>>> {
|
||||||
match self {
|
match self {
|
||||||
Self::Element(e) => Some(&e.opening_element.attributes),
|
Self::Element(e) if !e.opening_element.attributes.is_empty() => {
|
||||||
Self::Fragment(_) => None,
|
Some(&e.opening_element.attributes)
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,12 +127,6 @@ impl<'a> ReactJsx<'a> {
|
||||||
JSXElementOrFragment::Fragment(_) => self.get_fragment(),
|
JSXElementOrFragment::Fragment(_) => self.get_fragment(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if self.options.runtime.is_classic() && e.attributes().is_some_and(|attrs| attrs.is_empty())
|
|
||||||
{
|
|
||||||
let null_expr = self.ast.literal_null_expression(NullLiteral::new(SPAN));
|
|
||||||
arguments.push(Argument::Expression(null_expr));
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: compute the correct capacity for both runtimes
|
// TODO: compute the correct capacity for both runtimes
|
||||||
let mut properties = self.ast.new_vec_with_capacity(0);
|
let mut properties = self.ast.new_vec_with_capacity(0);
|
||||||
if let Some(attributes) = e.attributes() {
|
if let Some(attributes) = e.attributes() {
|
||||||
|
|
@ -196,6 +192,9 @@ impl<'a> ReactJsx<'a> {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if self.options.runtime.is_classic() {
|
||||||
|
let null_expr = self.ast.literal_null_expression(NullLiteral::new(SPAN));
|
||||||
|
arguments.push(Argument::Expression(null_expr));
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.options.runtime.is_automatic() && !children.is_empty() {
|
if self.options.runtime.is_automatic() && !children.is_empty() {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
Passed: 204/1083
|
Passed: 206/1083
|
||||||
|
|
||||||
# All Passed:
|
# All Passed:
|
||||||
* babel-plugin-transform-numeric-separator
|
* babel-plugin-transform-numeric-separator
|
||||||
|
|
@ -804,7 +804,7 @@ Passed: 204/1083
|
||||||
* regression/11061/input.mjs
|
* regression/11061/input.mjs
|
||||||
* variable-declaration/non-null-in-optional-chain/input.ts
|
* variable-declaration/non-null-in-optional-chain/input.ts
|
||||||
|
|
||||||
# babel-plugin-transform-react-jsx (55/172)
|
# babel-plugin-transform-react-jsx (57/172)
|
||||||
* autoImport/after-polyfills/input.mjs
|
* autoImport/after-polyfills/input.mjs
|
||||||
* autoImport/after-polyfills-2/input.mjs
|
* autoImport/after-polyfills-2/input.mjs
|
||||||
* autoImport/after-polyfills-compiled-to-cjs/input.mjs
|
* autoImport/after-polyfills-compiled-to-cjs/input.mjs
|
||||||
|
|
@ -836,7 +836,6 @@ Passed: 204/1083
|
||||||
* react/arrow-functions/input.js
|
* react/arrow-functions/input.js
|
||||||
* react/assignment-babel-7/input.js
|
* react/assignment-babel-7/input.js
|
||||||
* react/avoids-spread-babel-7/input.js
|
* react/avoids-spread-babel-7/input.js
|
||||||
* react/does-not-add-source-self/input.mjs
|
|
||||||
* react/does-not-add-source-self-babel-7/input.mjs
|
* react/does-not-add-source-self-babel-7/input.mjs
|
||||||
* react/flattens-spread/input.js
|
* react/flattens-spread/input.js
|
||||||
* react/handle-spread-with-proto/input.js
|
* react/handle-spread-with-proto/input.js
|
||||||
|
|
@ -849,7 +848,6 @@ Passed: 204/1083
|
||||||
* react/should-add-quotes-es3/input.js
|
* react/should-add-quotes-es3/input.js
|
||||||
* react/should-allow-elements-as-attributes/input.js
|
* react/should-allow-elements-as-attributes/input.js
|
||||||
* react/should-allow-jsx-docs-comment-with-pragma/input.js
|
* react/should-allow-jsx-docs-comment-with-pragma/input.js
|
||||||
* react/should-allow-nested-fragments/input.js
|
|
||||||
* react/should-allow-no-pragmafrag-if-frag-unused/input.js
|
* react/should-allow-no-pragmafrag-if-frag-unused/input.js
|
||||||
* react/should-allow-pragmafrag-and-frag/input.js
|
* react/should-allow-pragmafrag-and-frag/input.js
|
||||||
* react/should-disallow-spread-children/input.js
|
* react/should-disallow-spread-children/input.js
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,7 @@ impl TestCase for ConformanceTestCase {
|
||||||
println!("{input}\n");
|
println!("{input}\n");
|
||||||
println!("Options:");
|
println!("Options:");
|
||||||
println!("{:?}\n", self.transform_options());
|
println!("{:?}\n", self.transform_options());
|
||||||
println!("Output:\n");
|
println!("Expected:\n");
|
||||||
println!("{output}\n");
|
println!("{output}\n");
|
||||||
println!("Transformed:\n");
|
println!("Transformed:\n");
|
||||||
println!("{transformed_code}\n");
|
println!("{transformed_code}\n");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue