Skip to content

Commit d975f80

Browse files
alangpiercecpojer
authored andcommitted
Fix crash due to skipped children in create-element-to-jsx (#81)
In #79, I made it so the transformation is skipped in some cases, in particular when the capitalization is invalid. This broke an assumption elsewhere in the code that `convertNodeToJSX` always returns a `JSXElement`, so there was a crash if a skipped element was used as a child. To fix, we can just wrap in a `JSXExpressionContainer` for that case.
1 parent 83efb64 commit d975f80

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

transforms/__testfixtures__/create-element-to-jsx-ignore-bad-capitalization.input.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ React.createElement('foo');
77
React.createElement(_foo);
88
React.createElement('_foo');
99
React.createElement(foo.bar);
10+
React.createElement(Foo, null, React.createElement(foo));

transforms/__testfixtures__/create-element-to-jsx-ignore-bad-capitalization.output.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ React.createElement('Foo');
77
<_foo />;
88
React.createElement('_foo');
99
<foo.bar />;
10+
<Foo>{React.createElement(foo)}</Foo>;

transforms/create-element-to-jsx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ module.exports = function(file, api, options) {
170170
child.callee.object.name === 'React' &&
171171
child.callee.property.name === 'createElement') {
172172
const jsxChild = convertNodeToJSX(node.get('arguments', index + 2));
173-
if ((jsxChild.comments || []).length > 0) {
173+
if (jsxChild.type !== 'JSXElement' || (jsxChild.comments || []).length > 0) {
174174
return j.jsxExpressionContainer(jsxChild);
175175
} else {
176176
return jsxChild;

0 commit comments

Comments
 (0)