Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Allow for a callExpression as child that's not an element.
The previous code assumed that all children that were of type CallExpression were in fact calls on MemberExpressions. This fix makes sure we also support other calls.
  • Loading branch information
Remon Oldenbeuving committed Dec 10, 2015
commit c2af795ac31cf0d52f7fc4e17991e93ac6a7e89c
2 changes: 2 additions & 0 deletions test/__tests__/create-element-to-jsx-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ describe('create-element-to-jsx', () => {
test('create-element-to-jsx', 'create-element-to-jsx-no-react');

test('create-element-to-jsx', 'create-element-to-jsx-literal-prop');

test('create-element-to-jsx', 'create-element-to-jsx-call-as-children');
});

});
3 changes: 3 additions & 0 deletions test/create-element-to-jsx-call-as-children.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var React = require('react/addons');

React.createElement('div', {}, foo());
3 changes: 3 additions & 0 deletions test/create-element-to-jsx-call-as-children.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var React = require('react/addons');

<div>{foo()}</div>;
1 change: 1 addition & 0 deletions transforms/create-element-to-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module.exports = function(file, api, options) {
if (child.type === 'Literal' && typeof child.value === 'string') {
return j.jsxText(child.value);
} else if (child.type === 'CallExpression' &&
child.callee.object &&
child.callee.object.name === 'React' &&
child.callee.property.name === 'createElement') {
return convertNodeToJSX(node.get('arguments', index + 2));
Expand Down