From 5f3ed3f7241df57cfbc98edabf84100ceea7bfb1 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Fri, 8 Mar 2024 13:59:21 -0800 Subject: [PATCH] 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. --- ...reassign-in-while-loop-condition.expect.md | 38 +++++++++++++++++++ ...r.todo-reassign-in-while-loop-condition.js | 17 +++++++++ 2 files changed, 55 insertions(+) create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-in-while-loop-condition.expect.md create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-in-while-loop-condition.js diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-in-while-loop-condition.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-in-while-loop-condition.expect.md new file mode 100644 index 0000000000..94a9cb8000 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-in-while-loop-condition.expect.md @@ -0,0 +1,38 @@ + +## Input + +```javascript +import { makeArray } from "shared-runtime"; + +// @flow +function Component() { + const items = makeArray(0, 1, 2); + let item; + let sum = 0; + while ((item = items.pop())) { + sum += item; + } + return [sum]; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{}], +}; + +``` + + +## Error + +``` + 6 | let item; + 7 | let sum = 0; +> 8 | while ((item = items.pop())) { + | ^^^^ [ReactForget] Invariant: Unexpected StoreLocal in codegenInstructionValue (8:8) + 9 | sum += item; + 10 | } + 11 | return [sum]; +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-in-while-loop-condition.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-in-while-loop-condition.js new file mode 100644 index 0000000000..1bd95da06a --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-in-while-loop-condition.js @@ -0,0 +1,17 @@ +import { makeArray } from "shared-runtime"; + +// @flow +function Component() { + const items = makeArray(0, 1, 2); + let item; + let sum = 0; + while ((item = items.pop())) { + sum += item; + } + return [sum]; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{}], +};