React inlining: Fix transform for computed key
(This was broken before my last change too.)
This commit is contained in:
@@ -12,6 +12,13 @@ export default function ({ types: t }) {
|
||||
return t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name, { name: name });
|
||||
}
|
||||
|
||||
function getAttributeValue(attr) {
|
||||
let value = attr.value;
|
||||
if (!value) return t.identifier("true");
|
||||
if (t.isJSXExpressionContainer(value)) value = value.expression;
|
||||
return value;
|
||||
}
|
||||
|
||||
return {
|
||||
visitor: {
|
||||
JSXElement(path, file) {
|
||||
@@ -33,18 +40,17 @@ export default function ({ types: t }) {
|
||||
}
|
||||
|
||||
function pushProp(objProps, key, value) {
|
||||
if (t.isJSXExpressionContainer(value)) value = value.expression;
|
||||
objProps.push(t.objectProperty(key, value));
|
||||
}
|
||||
|
||||
// props
|
||||
for (let attr of (open.attributes: Array<Object>)) {
|
||||
if (isJSXAttributeOfName(attr, "key")) {
|
||||
key = attr.value;
|
||||
key = getAttributeValue(attr);
|
||||
} else {
|
||||
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"));
|
||||
pushProp(props.properties, propertyKey, getAttributeValue(attr));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<Foo key={"foo" + "baz"} data-value="bar" />
|
||||
@@ -0,0 +1,3 @@
|
||||
babelHelpers.createRawReactElement(Foo, "foo" + "baz", babelHelpers.defaultProps(Foo.defaultProps, {
|
||||
"data-value": "bar"
|
||||
}));
|
||||
Reference in New Issue
Block a user