transformation-react-inline-elements: ensure invalid identifier JSX attribute keys are quoted - fixes #2808

This commit is contained in:
Henry Zhu
2015-11-04 08:47:09 -05:00
parent 232439460f
commit f01d2054d4
3 changed files with 8 additions and 4 deletions

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"));
}
}