@samitouri / QOS-React-2 / commits / 0ee5e482a2

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

Joe Savona committed Mar 23, 2023 at 09:01 UTC 0ee5e482a2ef03b332ca5a6df93c839aa95e584a
3 files changed +36
compiler/forget/src/HIR/BuildHIR.ts
+7
@@ -1744,6 +1744,13 @@ function lowerMemberExpression(
1744 },
1745 };
1746 }
1747 + if (t.isOptionalMemberExpression(expr)) {
1748 + builder.errors.push({
1749 + reason: `(BuildHIR::lowerMemberExpression) Handle computed OptionalMemberExpression`,
1750 + severity: ErrorSeverity.Todo,
1751 + nodePath: expr,
1752 + });
1753 + }
1754 const propertyPlace = lowerExpressionToTemporary(builder, property);
1755 const value: InstructionValue = {
1756 kind: "ComputedLoad",
compiler/forget/src/__tests__/fixtures/compiler/error.optional-computed-member-expression.expect.md new
+25
@@ -0,0 +1,25 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function Component(props) {
6 + const object = makeObject(props);
7 + return object?.[props.key];
8 +}
9 +
10 +```
11 +
12 +
13 +## Error
14 +
15 +```
16 +[ReactForget] TodoError: (BuildHIR::lowerMemberExpression) Handle computed OptionalMemberExpression
17 + 1 | function Component(props) {
18 + 2 | const object = makeObject(props);
19 +> 3 | return object?.[props.key];
20 + | ^^^^^^^^^^^^^^^^^^^
21 + 4 | }
22 + 5 |
23 +```
24 +
25 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/error.optional-computed-member-expression.js new
+4
@@ -0,0 +1,4 @@
1 +function Component(props) {
2 + const object = makeObject(props);
3 + return object?.[props.key];
4 +}