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:
committed by
Logan Smyth
parent
63157159ab
commit
e9ed687666
@@ -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;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<><span /><div /></>
|
||||
@@ -0,0 +1 @@
|
||||
React.createElement(React.Fragment, null, babelHelpers.jsx("span", {}), babelHelpers.jsx("div", {}));
|
||||
Reference in New Issue
Block a user