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