Merge pull request #2811 from hzoo/i-2808

transformation-react-inline-elements: ensure invalid identifier JSX attribute keys are quoted - fixes #2808
This commit is contained in:
Sebastian McKenzie 2015-11-04 19:16:32 +00:00
commit 9680bf6a68
3 changed files with 8 additions and 4 deletions

View File

@ -1 +1 @@
<Foo key="foo" />
<Foo key="foo" data-value="bar" />

View File

@ -3,6 +3,8 @@
type: Foo,
key: "foo",
ref: null,
props: babelHelpers.defaultProps(Foo.defaultProps, {}),
props: babelHelpers.defaultProps(Foo.defaultProps, {
"data-value": "bar"
}),
_owner: null
});
});

View File

@ -55,7 +55,9 @@ export default function ({ types: t }) {
if (isJSXAttributeOfName(attr, "key")) {
key = attr.value;
} else {
pushProp(props.properties, t.identifier(attr.name.name), attr.value || t.identifier("true"));
let name = attr.name.name;
let propertyKey = t.isValidIdentifier(name) ? t.identifier(name) : t.stringLiteral(name);
pushProp(props.properties, propertyKey, attr.value || t.identifier("true"));
}
}