mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Support string literal keys for object expressions
For ObjectExpression, we now support computed keys where the key is a string literal.
This commit is contained in:
@@ -809,7 +809,12 @@ function lowerExpression(
|
||||
continue;
|
||||
}
|
||||
const key = propertyPath.node.key;
|
||||
if (key.type !== "Identifier") {
|
||||
let keyName: string;
|
||||
if (key.type === "Identifier") {
|
||||
keyName = key.name;
|
||||
} else if (key.type === "StringLiteral") {
|
||||
keyName = key.value;
|
||||
} else {
|
||||
builder.errors.push({
|
||||
reason: `(BuildHIR::lowerExpression) Expected Identifier, got ${key.type} key in ObjectExpression`,
|
||||
severity: ErrorSeverity.InvalidInput,
|
||||
@@ -827,7 +832,7 @@ function lowerExpression(
|
||||
continue;
|
||||
}
|
||||
const value = lowerExpressionToTemporary(builder, valuePath);
|
||||
properties.set(key.name, value);
|
||||
properties.set(keyName, value);
|
||||
}
|
||||
return {
|
||||
kind: "ObjectExpression",
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function Component(props) {
|
||||
const x = { ["foo"]: props.foo };
|
||||
return x;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
function Component(props) {
|
||||
const $ = React.unstable_useMemoCache(2);
|
||||
const c_0 = $[0] !== props.foo;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = { foo: props.foo };
|
||||
$[0] = props.foo;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
t0 = $[1];
|
||||
}
|
||||
const x = t0;
|
||||
return x;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
function Component(props) {
|
||||
const x = { ["foo"]: props.foo };
|
||||
return x;
|
||||
}
|
||||
Reference in New Issue
Block a user