From da20aa90c1d7c5d932c53717352c0e70116768ad Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 8 Nov 2015 17:10:33 -0800 Subject: [PATCH] omit defaultProps helper when there are no props --- .../component/expected.js | 4 ++-- .../multiline/expected.js | 2 +- .../nested-components/expected.js | 2 +- .../optimisation.react.inline-elements/nested/expected.js | 2 +- .../self-closing-component/expected.js | 4 ++-- .../src/index.js | 7 ++++++- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/component/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/component/expected.js index ecdf28d80c..629cd8964d 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/component/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/component/expected.js @@ -3,6 +3,6 @@ type: Baz, key: null, ref: null, - props: babelHelpers.defaultProps(Baz.defaultProps, {}), + props: Baz.defaultProps, _owner: null -}); \ No newline at end of file +}); 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 index d2efb36450..629cd8964d 100644 --- 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 @@ -3,6 +3,6 @@ type: Baz, key: null, ref: null, - props: babelHelpers.defaultProps(Baz.defaultProps, {}), + props: Baz.defaultProps, _owner: null }); diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested-components/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested-components/expected.js index 9dd292a902..aa56b62cad 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested-components/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested-components/expected.js @@ -10,7 +10,7 @@ type: Baz, key: "baz", ref: null, - props: babelHelpers.defaultProps(Baz.defaultProps, {}), + props: Baz.defaultProps, _owner: null }] }), diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested/expected.js index 24cea8512c..77f52b9fae 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested/expected.js @@ -10,7 +10,7 @@ type: Baz, key: "baz", ref: null, - props: babelHelpers.defaultProps(Baz.defaultProps, {}), + props: Baz.defaultProps, _owner: null }] }, diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component/expected.js index ecdf28d80c..629cd8964d 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component/expected.js @@ -3,6 +3,6 @@ type: Baz, key: null, ref: null, - props: babelHelpers.defaultProps(Baz.defaultProps, {}), + props: Baz.defaultProps, _owner: null -}); \ No newline at end of file +}); 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 93fc13c2f3..e7be6d181f 100644 --- a/packages/babel-plugin-transform-react-inline-elements/src/index.js +++ b/packages/babel-plugin-transform-react-inline-elements/src/index.js @@ -62,7 +62,12 @@ export default function ({ types: t }) { } if (isComponent) { - props = t.callExpression(file.addHelper("defaultProps"), [t.memberExpression(type, t.identifier("defaultProps")), props]); + let defProps = t.memberExpression(type, t.identifier("defaultProps")); + if (props.properties.length) { + props = t.callExpression(file.addHelper("defaultProps"), [defProps, props]); + } else { + props = defProps; + } } // metadata