feat(transformer/react-jsx): support for throwing SpreadChildrenAreNotSupported error (#1234)

This commit is contained in:
Dunqing 2023-11-12 18:37:19 +08:00 committed by GitHub
parent 72b3bdf619
commit 1eef241788
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -37,6 +37,11 @@ struct NamespaceDoesNotSupport(#[label] Span);
#[diagnostic(severity(warning))] #[diagnostic(severity(warning))]
struct ValuelessKey(#[label] Span); struct ValuelessKey(#[label] Span);
#[derive(Debug, Error, Diagnostic)]
#[error("Spread children are not supported in React.")]
#[diagnostic(severity(warning))]
struct SpreadChildrenAreNotSupported(#[label] Span);
/// Transform React JSX /// Transform React JSX
/// ///
/// References: /// References:
@ -370,6 +375,12 @@ impl<'a> ReactJsx<'a> {
let children = e.children(); let children = e.children();
if children.len() == 1 {
if let Some(JSXChild::Spread(s)) = children.get(0) {
self.ctx.error(SpreadChildrenAreNotSupported(s.span));
}
}
// Append children to object properties in automatic mode // Append children to object properties in automatic mode
if is_automatic { if is_automatic {
let allocator = self.ast.allocator; let allocator = self.ast.allocator;

View file

@ -1,4 +1,4 @@
Passed: 275/1113 Passed: 277/1113
# All Passed: # All Passed:
* babel-plugin-transform-numeric-separator * babel-plugin-transform-numeric-separator
@ -852,7 +852,7 @@ Passed: 275/1113
* 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 (140/170) # babel-plugin-transform-react-jsx (142/170)
* autoImport/after-polyfills-compiled-to-cjs/input.mjs * autoImport/after-polyfills-compiled-to-cjs/input.mjs
* autoImport/complicated-scope-module/input.js * autoImport/complicated-scope-module/input.js
* react/adds-appropriate-newlines-when-using-spread-attribute-babel-7/input.js * react/adds-appropriate-newlines-when-using-spread-attribute-babel-7/input.js
@ -863,14 +863,12 @@ Passed: 275/1113
* react/handle-spread-with-proto-babel-7/input.js * react/handle-spread-with-proto-babel-7/input.js
* react/optimisation.react.constant-elements/input.js * react/optimisation.react.constant-elements/input.js
* react/should-add-quotes-es3/input.js * react/should-add-quotes-es3/input.js
* react/should-disallow-spread-children/input.js
* react/wraps-props-in-react-spread-for-first-spread-attributes-babel-7/input.js * react/wraps-props-in-react-spread-for-first-spread-attributes-babel-7/input.js
* react/wraps-props-in-react-spread-for-last-spread-attributes-babel-7/input.js * 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/wraps-props-in-react-spread-for-middle-spread-attributes-babel-7/input.js
* react-automatic/arrow-functions/input.js * react-automatic/arrow-functions/input.js
* react-automatic/optimisation.react.constant-elements/input.js * react-automatic/optimisation.react.constant-elements/input.js
* react-automatic/should-add-quotes-es3/input.js * react-automatic/should-add-quotes-es3/input.js
* react-automatic/should-disallow-spread-children/input.js
* react-automatic/should-handle-attributed-elements/input.js * react-automatic/should-handle-attributed-elements/input.js
* react-automatic/should-throw-when-filter-is-specified/input.js * react-automatic/should-throw-when-filter-is-specified/input.js
* regression/issue-12478-automatic/input.js * regression/issue-12478-automatic/input.js