mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
feat(transformer/react-jsx): support for throwing SpreadChildrenAreNotSupported error (#1234)
This commit is contained in:
parent
72b3bdf619
commit
1eef241788
2 changed files with 13 additions and 4 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue