diff --git a/packages/babel-core/test/fixtures/transformation/react/should-quote-jsx-attributes/actual.js b/packages/babel-core/test/fixtures/transformation/react/should-quote-jsx-attributes/actual.js new file mode 100644 index 0000000000..c794650e94 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/react/should-quote-jsx-attributes/actual.js @@ -0,0 +1 @@ +; diff --git a/packages/babel-core/test/fixtures/transformation/react/should-quote-jsx-attributes/expected.js b/packages/babel-core/test/fixtures/transformation/react/should-quote-jsx-attributes/expected.js new file mode 100644 index 0000000000..1f01a22149 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/react/should-quote-jsx-attributes/expected.js @@ -0,0 +1,5 @@ +React.createElement( + 'button', + { 'data-value': 'a value' }, + 'Button' +); diff --git a/packages/babel-helper-builder-react-jsx/src/index.js b/packages/babel-helper-builder-react-jsx/src/index.js index 645c44a6da..558d6f789a 100644 --- a/packages/babel-helper-builder-react-jsx/src/index.js +++ b/packages/babel-helper-builder-react-jsx/src/index.js @@ -1,6 +1,5 @@ /* @flow */ -import isString from "lodash/lang/isString"; import esutils from "esutils"; import * as t from "babel-types"; @@ -66,11 +65,15 @@ export default function (opts) { function convertAttribute(node) { let value = convertAttributeValue(node.value || t.booleanLiteral(true)); - if (t.isLiteral(value) && isString(value.value)) { + if (t.isStringLiteral(value)) { value.value = value.value.replace(/\n\s+/g, " "); } - node.name.type = "Identifier"; + if (t.isValidIdentifier(node.name.name)) { + node.name.type = "Identifier"; + } else { + node.name = t.stringLiteral(node.name.name); + } return t.inherits(t.objectProperty(node.name, value), node); }