mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Optional computed member expressions are not supported (add validation)
We don't propagate the `optional` flag through to codegen, so let's error on this for now
This commit is contained in:
@@ -1744,6 +1744,13 @@ function lowerMemberExpression(
|
||||
},
|
||||
};
|
||||
}
|
||||
if (t.isOptionalMemberExpression(expr)) {
|
||||
builder.errors.push({
|
||||
reason: `(BuildHIR::lowerMemberExpression) Handle computed OptionalMemberExpression`,
|
||||
severity: ErrorSeverity.Todo,
|
||||
nodePath: expr,
|
||||
});
|
||||
}
|
||||
const propertyPlace = lowerExpressionToTemporary(builder, property);
|
||||
const value: InstructionValue = {
|
||||
kind: "ComputedLoad",
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function Component(props) {
|
||||
const object = makeObject(props);
|
||||
return object?.[props.key];
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Error
|
||||
|
||||
```
|
||||
[ReactForget] TodoError: (BuildHIR::lowerMemberExpression) Handle computed OptionalMemberExpression
|
||||
1 | function Component(props) {
|
||||
2 | const object = makeObject(props);
|
||||
> 3 | return object?.[props.key];
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
4 | }
|
||||
5 |
|
||||
```
|
||||
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
function Component(props) {
|
||||
const object = makeObject(props);
|
||||
return object?.[props.key];
|
||||
}
|
||||
Reference in New Issue
Block a user