From 2a1a0380318787d246eab593a81ca6ce961d7174 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 8 Nov 2015 06:24:10 -0800 Subject: [PATCH] move children prop pushing to after props to ensure correct order - fixes #2395 --- .../children-exists/actual.js | 1 + .../children-exists/expected.js | 11 +++++++++++ .../src/index.js | 16 ++++++++-------- 3 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/children-exists/actual.js create mode 100644 packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/children-exists/expected.js diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/children-exists/actual.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/children-exists/actual.js new file mode 100644 index 0000000000..50162d7db8 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/children-exists/actual.js @@ -0,0 +1 @@ +
bar
; diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/children-exists/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/children-exists/expected.js new file mode 100644 index 0000000000..e9eb914ecc --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/children-exists/expected.js @@ -0,0 +1,11 @@ +({ + $$typeof: babelHelpers.typeofReactElement, + type: "div", + key: null, + ref: null, + props: { + children: "foo", + children: "bar" + }, + _owner: null +}); diff --git a/packages/babel-plugin-transform-react-inline-elements/src/index.js b/packages/babel-plugin-transform-react-inline-elements/src/index.js index 112c47af4f..93fc13c2f3 100644 --- a/packages/babel-plugin-transform-react-inline-elements/src/index.js +++ b/packages/babel-plugin-transform-react-inline-elements/src/index.js @@ -42,14 +42,6 @@ export default function ({ types: t }) { objProps.push(t.objectProperty(key, value)); } - if (node.children.length) { - let children = t.react.buildChildren(node); - if (children.length) { - children = children.length === 1 ? children[0] : t.arrayExpression(children); - pushProp(props.properties, t.identifier("children"), children); - } - } - // props for (let attr of (open.attributes: Array)) { if (isJSXAttributeOfName(attr, "key")) { @@ -61,6 +53,14 @@ export default function ({ types: t }) { } } + if (node.children.length) { + let children = t.react.buildChildren(node); + if (children.length) { + children = children.length === 1 ? children[0] : t.arrayExpression(children); + pushProp(props.properties, t.identifier("children"), children); + } + } + if (isComponent) { props = t.callExpression(file.addHelper("defaultProps"), [t.memberExpression(type, t.identifier("defaultProps")), props]); }