Bail out on JSX fragments instead of throwing (#7166)

* Bail out on JSX fragments instead of throwing

The `transform-react-inline-elements` plugin doesn't handle JSX fragments. It throws an exception because `node.openingElement` is undefined.

* Add a comment explaining `node.openingElement`
This commit is contained in:
Mouad Debbar
2018-01-09 08:38:52 +03:00
committed by Logan Smyth
parent 63157159ab
commit e9ed687666
3 changed files with 7 additions and 1 deletions

View File

@@ -19,7 +19,11 @@ export default function() {
const visitor = helper({
filter(node) {
return !hasRefOrSpread(node.openingElement.attributes);
return (
// Regular JSX nodes have an `openingElement`. JSX fragments, however, don't have an
// `openingElement` which causes `node.openingElement.attributes` to throw.
node.openingElement && !hasRefOrSpread(node.openingElement.attributes)
);
},
pre(state) {
const tagName = state.tagName;

View File

@@ -0,0 +1 @@
<><span /><div /></>

View File

@@ -0,0 +1 @@
React.createElement(React.Fragment, null, babelHelpers.jsx("span", {}), babelHelpers.jsx("div", {}));