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:
Joe Savona
2023-03-23 09:01:21 -07:00
parent ef83c02d3c
commit 0ee5e482a2
3 changed files with 36 additions and 0 deletions
+7
View File
@@ -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",
@@ -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 |
```
@@ -0,0 +1,4 @@
function Component(props) {
const object = makeObject(props);
return object?.[props.key];
}