diff --git a/packages/babel-helper-builder-react-jsx/src/index.js b/packages/babel-helper-builder-react-jsx/src/index.js index 4f2473ae50..3602ecb849 100644 --- a/packages/babel-helper-builder-react-jsx/src/index.js +++ b/packages/babel-helper-builder-react-jsx/src/index.js @@ -19,6 +19,13 @@ You can turn on the 'throwIfNamespace' flag to bypass this warning.`, ); } }; + + visitor.JSXSpreadChild = function(path) { + throw path.buildCodeFrameError( + "Spread children are not supported in React.", + ); + }; + visitor.JSXElement = { exit(path, file) { const callExpr = buildElementCall(path, file); diff --git a/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-disallow-spread-children/input.js b/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-disallow-spread-children/input.js new file mode 100644 index 0000000000..6a05e108dc --- /dev/null +++ b/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-disallow-spread-children/input.js @@ -0,0 +1 @@ +
{...children}
; diff --git a/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-disallow-spread-children/options.json b/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-disallow-spread-children/options.json new file mode 100644 index 0000000000..bcb773e343 --- /dev/null +++ b/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-disallow-spread-children/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Spread children are not supported in React." +}