From b98d24594a4f0c55908dd3115c48493c6bd42e46 Mon Sep 17 00:00:00 2001 From: Samuel Reed Date: Thu, 29 Oct 2015 21:18:07 -0500 Subject: [PATCH] optimisations.react.inline: don't pass empty array. This fixes incompatibilities with code that check for the existence of children. --- .../multiline/actual.js | 2 ++ .../multiline/expected.js | 10 ++++++++++ .../src/index.js | 6 ++++-- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/multiline/actual.js create mode 100644 packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/multiline/expected.js diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/multiline/actual.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/multiline/actual.js new file mode 100644 index 0000000000..b9d702f6f3 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/multiline/actual.js @@ -0,0 +1,2 @@ + +; diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/multiline/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/multiline/expected.js new file mode 100644 index 0000000000..84efbdfec2 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/multiline/expected.js @@ -0,0 +1,10 @@ +"use strict"; + +({ + $$typeof: babelHelpers.typeofReactElement, + type: Baz, + key: null, + ref: null, + props: babelHelpers.defaultProps(Baz.defaultProps, {}), + _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 deae408c08..9d6b307f3c 100644 --- a/packages/babel-plugin-transform-react-inline-elements/src/index.js +++ b/packages/babel-plugin-transform-react-inline-elements/src/index.js @@ -43,8 +43,10 @@ export default function ({ types: t }) { if (node.children.length) { let children = t.react.buildChildren(node); - children = children.length === 1 ? children[0] : t.arrayExpression(children); - pushProp(props.properties, t.identifier("children"), children); + if (children.length) { + children = children.length === 1 ? children[0] : t.arrayExpression(children); + pushProp(props.properties, t.identifier("children"), children); + } } // props