@samitouri / QOS-React-2 / commits / f3d4d16918

[lower] Bail out on computed lvalues in destructure

--- Currently, we're silently producing incorrect output - ```js // source function Component(props) { const computedKey = props.key; const { [computedKey]: x } = props.val; return x; } // compiles to function Component(props) { const { computedKey: x } = props.val; return x; } ```

Mofei Zhang committed May 9, 2023 at 14:38 UTC f3d4d1691819c58c6f9e42b113750685ab647dd0
3 files changed +42
compiler/forget/src/HIR/BuildHIR.ts
+8
@@ -2586,6 +2586,14 @@ function lowerAssignment(
2586 });
2587 continue;
2588 }
2589 + if (property.node.computed) {
2590 + builder.errors.push({
2591 + reason: `(BuildHIR::lowerAssignment) Handle computed properties in ObjectPattern`,
2592 + severity: ErrorSeverity.Todo,
2593 + nodePath: property,
2594 + });
2595 + continue;
2596 + }
2597 const key = property.get("key");
2598 if (!key.isIdentifier()) {
2599 builder.errors.push({
compiler/forget/src/__tests__/fixtures/compiler/error._todo.computed-lval-in-destructure.expect.md new
+28
@@ -0,0 +1,28 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function Component(props) {
6 + const computedKey = props.key;
7 + const { [computedKey]: x } = props.val;
8 +
9 + return x;
10 +}
11 +
12 +```
13 +
14 +
15 +## Error
16 +
17 +```
18 +[ReactForget] TodoError: (BuildHIR::lowerAssignment) Handle computed properties in ObjectPattern
19 + 1 | function Component(props) {
20 + 2 | const computedKey = props.key;
21 +> 3 | const { [computedKey]: x } = props.val;
22 + | ^^^^^^^^^^^^^^^^
23 + 4 |
24 + 5 | return x;
25 + 6 | }
26 +```
27 +
28 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/error._todo.computed-lval-in-destructure.js new
+6
@@ -0,0 +1,6 @@
1 +function Component(props) {
2 + const computedKey = props.key;
3 + const { [computedKey]: x } = props.val;
4 +
5 + return x;
6 +}