@samitouri / QOS-React-2 / commits / 5f3ed3f724

Fixture for reassignment within value block

Fixture from T175283039, a reassignment within an expression can sometimes generate a StoreLocal within a value block. Depending on the case this can end up as the last instruction of the block, which then hits an invariant.

Joe Savona committed Mar 8, 2024 at 13:59 UTC 5f3ed3f7241df57cfbc98edabf84100ceea7bfb1
2 files changed +55
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-in-while-loop-condition.expect.md new
+38
@@ -0,0 +1,38 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +import { makeArray } from "shared-runtime";
6 +
7 +// @flow
8 +function Component() {
9 + const items = makeArray(0, 1, 2);
10 + let item;
11 + let sum = 0;
12 + while ((item = items.pop())) {
13 + sum += item;
14 + }
15 + return [sum];
16 +}
17 +
18 +export const FIXTURE_ENTRYPOINT = {
19 + fn: Component,
20 + params: [{}],
21 +};
22 +
23 +```
24 +
25 +
26 +## Error
27 +
28 +```
29 + 6 | let item;
30 + 7 | let sum = 0;
31 +> 8 | while ((item = items.pop())) {
32 + | ^^^^ [ReactForget] Invariant: Unexpected StoreLocal in codegenInstructionValue (8:8)
33 + 9 | sum += item;
34 + 10 | }
35 + 11 | return [sum];
36 +```
37 +
38 +
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-in-while-loop-condition.js new
+17
@@ -0,0 +1,17 @@
1 +import { makeArray } from "shared-runtime";
2 +
3 +// @flow
4 +function Component() {
5 + const items = makeArray(0, 1, 2);
6 + let item;
7 + let sum = 0;
8 + while ((item = items.pop())) {
9 + sum += item;
10 + }
11 + return [sum];
12 +}
13 +
14 +export const FIXTURE_ENTRYPOINT = {
15 + fn: Component,
16 + params: [{}],
17 +};