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:
commit
9680bf6a68
@ -1 +1 @@
|
|||||||
<Foo key="foo" />
|
<Foo key="foo" data-value="bar" />
|
||||||
|
|||||||
@ -3,6 +3,8 @@
|
|||||||
type: Foo,
|
type: Foo,
|
||||||
key: "foo",
|
key: "foo",
|
||||||
ref: null,
|
ref: null,
|
||||||
props: babelHelpers.defaultProps(Foo.defaultProps, {}),
|
props: babelHelpers.defaultProps(Foo.defaultProps, {
|
||||||
|
"data-value": "bar"
|
||||||
|
}),
|
||||||
_owner: null
|
_owner: null
|
||||||
});
|
});
|
||||||
|
|||||||
@ -55,7 +55,9 @@ export default function ({ types: t }) {
|
|||||||
if (isJSXAttributeOfName(attr, "key")) {
|
if (isJSXAttributeOfName(attr, "key")) {
|
||||||
key = attr.value;
|
key = attr.value;
|
||||||
} else {
|
} 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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user