diff --git a/compiler/forget/src/SSA/EnterSSA.ts b/compiler/forget/src/SSA/EnterSSA.ts index e35f3664a4..0f6f9ec5c1 100644 --- a/compiler/forget/src/SSA/EnterSSA.ts +++ b/compiler/forget/src/SSA/EnterSSA.ts @@ -226,4 +226,12 @@ export default function enterSSA(func: HIRFunction) { } } } + + for (const [_, block] of func.body.blocks) { + for (const instr of block.instructions) { + if (instr.value.kind === "FunctionExpression") { + mapInstructionOperands(instr, (place) => builder.getPlace(place)); + } + } + } } diff --git a/compiler/forget/src/__tests__/fixtures/hir/mutate-captured-arg-separately.expect.md b/compiler/forget/src/__tests__/fixtures/hir/mutate-captured-arg-separately.expect.md new file mode 100644 index 0000000000..5745524c79 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/mutate-captured-arg-separately.expect.md @@ -0,0 +1,38 @@ + +## Input + +```javascript +function component(a) { + let y = function () { + m(x); + }; + + let x = { a }; + m(x); + return y; +} + +``` + +## Code + +```javascript +function component(a) { + const $ = React.useMemoCache(); + let y; + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { + y = function () { + m(x); + }; + $[0] = y; + } else { + y = $[0]; + } + + const x = { a: a }; + m(x); + return y; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/mutate-captured-arg-separately.js b/compiler/forget/src/__tests__/fixtures/hir/mutate-captured-arg-separately.js new file mode 100644 index 0000000000..5e083ec453 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/mutate-captured-arg-separately.js @@ -0,0 +1,9 @@ +function component(a) { + let y = function () { + m(x); + }; + + let x = { a }; + m(x); + return y; +}