From f6278e43ce6bc37a66f090a7499591574348e246 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 21 Apr 2015 16:14:36 +0100 Subject: [PATCH] properly handle shorthand JSX attributes in optimisation.react.inlineElements transformer - fixes #1309 --- .../transformers/optimisation/react.inline-elements.js | 2 +- .../shorthand-attributes/actual.js | 1 + .../shorthand-attributes/expected.js | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/core/fixtures/transformation/optimisation.react.inline-elements/shorthand-attributes/actual.js create mode 100644 test/core/fixtures/transformation/optimisation.react.inline-elements/shorthand-attributes/expected.js diff --git a/src/babel/transformation/transformers/optimisation/react.inline-elements.js b/src/babel/transformation/transformers/optimisation/react.inline-elements.js index 1e06ac833f..5c336788a2 100644 --- a/src/babel/transformation/transformers/optimisation/react.inline-elements.js +++ b/src/babel/transformation/transformers/optimisation/react.inline-elements.js @@ -57,7 +57,7 @@ export function JSXElement(node, parent, scope, file) { if (isJSXAttributeOfName(attr, "key")) { key = attr.value; } else { - pushProp(props.properties, attr.name, attr.value); + pushProp(props.properties, attr.name, attr.value || t.identifier("true")); } } diff --git a/test/core/fixtures/transformation/optimisation.react.inline-elements/shorthand-attributes/actual.js b/test/core/fixtures/transformation/optimisation.react.inline-elements/shorthand-attributes/actual.js new file mode 100644 index 0000000000..0545343f92 --- /dev/null +++ b/test/core/fixtures/transformation/optimisation.react.inline-elements/shorthand-attributes/actual.js @@ -0,0 +1 @@ +; diff --git a/test/core/fixtures/transformation/optimisation.react.inline-elements/shorthand-attributes/expected.js b/test/core/fixtures/transformation/optimisation.react.inline-elements/shorthand-attributes/expected.js new file mode 100644 index 0000000000..452322c2de --- /dev/null +++ b/test/core/fixtures/transformation/optimisation.react.inline-elements/shorthand-attributes/expected.js @@ -0,0 +1,10 @@ +"use strict"; + +({ + type: Foo, + ref: null, + props: babelHelpers.defaultProps(Foo.defaultProps, { + bar: true + }), + key: null +});