diff --git a/compiler/forget/src/__tests__/fixtures/hir/capturing-function-conditional-capture-mutate.expect.md b/compiler/forget/src/__tests__/fixtures/hir/capturing-function-conditional-capture-mutate.expect.md new file mode 100644 index 0000000000..9e2265fcce --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/capturing-function-conditional-capture-mutate.expect.md @@ -0,0 +1,54 @@ + +## Input + +```javascript +function component(a, b) { + let z = { a }; + let y = b; + let x = function () { + if (y) { + mutate(z); + } + }; + return x; +} + +``` + +## Code + +```javascript +function component(a, b) { + const $ = React.unstable_useMemoCache(5); + const c_0 = $[0] !== a; + let t0; + if (c_0) { + t0 = { a }; + $[0] = a; + $[1] = t0; + } else { + t0 = $[1]; + } + const z = t0; + const y = b; + const c_2 = $[2] !== y; + const c_3 = $[3] !== z; + let t1; + if (c_2 || c_3) { + t1 = function () { + if (y) { + mutate(z); + } + }; + $[2] = y; + $[3] = z; + $[4] = t1; + } else { + t1 = $[4]; + } + const x = t1; + return x; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/capturing-function-conditional-capture-mutate.js b/compiler/forget/src/__tests__/fixtures/hir/capturing-function-conditional-capture-mutate.js new file mode 100644 index 0000000000..10bac9e4df --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/capturing-function-conditional-capture-mutate.js @@ -0,0 +1,10 @@ +function component(a, b) { + let z = { a }; + let y = b; + let x = function () { + if (y) { + mutate(z); + } + }; + return x; +}