diff --git a/lib/6to5/transformation/transformers/react.js b/lib/6to5/transformation/transformers/react.js index 09bd579414..b19c39f22c 100644 --- a/lib/6to5/transformation/transformers/react.js +++ b/lib/6to5/transformation/transformers/react.js @@ -103,29 +103,22 @@ exports.XJSOpeningElement = { args.push(props); - var setPrettyPrint = function (call, args) { - if (args.length >= 3) { - call._prettyPrint = true; - } - return call; - }; - if (reactCompat) { if (tagName && isTag(tagName)) { - return setPrettyPrint(t.callExpression( + return t.callExpression( t.memberExpression( t.memberExpression(t.identifier("React"), t.identifier("DOM")), tagExpr, t.isLiteral(tagExpr) ), args - ), args); + ); } } else { tagExpr = t.memberExpression(t.identifier("React"), t.identifier("createElement")); } - return setPrettyPrint(t.callExpression(tagExpr, args), args); + return t.callExpression(tagExpr, args); } }; @@ -172,6 +165,10 @@ exports.XJSElement = { callExpr.arguments.push(child); } + if (callExpr.arguments.length >= 3) { + callExpr._prettyPrint = true; + } + return t.inherits(callExpr, node); } }; diff --git a/test/fixtures/transformation/react/should-avoid-wrapping-in-extra-parens-if-not-needed/expected.js b/test/fixtures/transformation/react/should-avoid-wrapping-in-extra-parens-if-not-needed/expected.js index fc3c313d70..300998b04d 100644 --- a/test/fixtures/transformation/react/should-avoid-wrapping-in-extra-parens-if-not-needed/expected.js +++ b/test/fixtures/transformation/react/should-avoid-wrapping-in-extra-parens-if-not-needed/expected.js @@ -1,7 +1,23 @@ -var x = React.createElement("div", null, React.createElement(Component, null)); +var x = React.createElement( + "div", + null, + React.createElement(Component, null) +); -var x = React.createElement("div", null, this.props.children); +var x = React.createElement( + "div", + null, + this.props.children +); -var x = React.createElement(Composite, null, this.props.children); +var x = React.createElement( + Composite, + null, + this.props.children +); -var x = React.createElement(Composite, null, React.createElement(Composite2, null)); +var x = React.createElement( + Composite, + null, + React.createElement(Composite2, null) +); diff --git a/test/fixtures/transformation/react/should-convert-simple-text/expected.js b/test/fixtures/transformation/react/should-convert-simple-text/expected.js index 4a89144887..0d70340e65 100644 --- a/test/fixtures/transformation/react/should-convert-simple-text/expected.js +++ b/test/fixtures/transformation/react/should-convert-simple-text/expected.js @@ -1 +1,5 @@ -var x = React.createElement("div", null, "text"); +var x = React.createElement( + "div", + null, + "text" +); diff --git a/test/fixtures/transformation/react/should-handle-has-own-property-correctly/expected.js b/test/fixtures/transformation/react/should-handle-has-own-property-correctly/expected.js index 55c8cea170..550edebb36 100644 --- a/test/fixtures/transformation/react/should-handle-has-own-property-correctly/expected.js +++ b/test/fixtures/transformation/react/should-handle-has-own-property-correctly/expected.js @@ -1 +1,5 @@ -React.createElement("hasOwnProperty", null, "testing"); +React.createElement( + "hasOwnProperty", + null, + "testing" +); diff --git a/test/fixtures/transformation/react/should-have-correct-comma-in-nested-children/expected.js b/test/fixtures/transformation/react/should-have-correct-comma-in-nested-children/expected.js index f8a0851173..5197540321 100644 --- a/test/fixtures/transformation/react/should-have-correct-comma-in-nested-children/expected.js +++ b/test/fixtures/transformation/react/should-have-correct-comma-in-nested-children/expected.js @@ -1 +1,17 @@ -var x = React.createElement("div", null, React.createElement("div", null, React.createElement("br", null)), React.createElement(Component, null, foo, React.createElement("br", null), bar), React.createElement("br", null)); +var x = React.createElement( + "div", + null, + React.createElement( + "div", + null, + React.createElement("br", null) + ), + React.createElement( + Component, + null, + foo, + React.createElement("br", null), + bar + ), + React.createElement("br", null) +);