diff --git a/compiler/forget/src/__tests__/fixtures/hir/capture-func-passed-to-jsx.expect.md b/compiler/forget/src/__tests__/fixtures/hir/capture-func-passed-to-jsx.expect.md new file mode 100644 index 0000000000..5284c0b814 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/capture-func-passed-to-jsx.expect.md @@ -0,0 +1,70 @@ + +## Input + +```javascript +function component(a, b) { + let y = { b }; + let z = { a }; + let x = function () { + z.a = 2; + y.b; + }; + let t = ; + mutate(x); // x should be frozen here + return t; +} + +``` + +## Code + +```javascript +function component(a, b) { + const $ = React.useMemoCache(); + const c_0 = $[0] !== b; + let y; + if (c_0) { + y = { b: b }; + $[0] = b; + $[1] = y; + } else { + y = $[1]; + } + const c_2 = $[2] !== a; + let z; + if (c_2) { + z = { a: a }; + $[2] = a; + $[3] = z; + } else { + z = $[3]; + } + const c_4 = $[4] !== z.a; + const c_5 = $[5] !== y.b; + let x; + if (c_4 || c_5) { + x = function () { + z.a = 2; + y.b; + }; + $[4] = z.a; + $[5] = y.b; + $[6] = x; + } else { + x = $[6]; + } + const c_7 = $[7] !== x; + let t; + if (c_7) { + t = ; + $[7] = x; + $[8] = t; + } else { + t = $[8]; + } + mutate(x); + return t; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/capture-func-passed-to-jsx.js b/compiler/forget/src/__tests__/fixtures/hir/capture-func-passed-to-jsx.js new file mode 100644 index 0000000000..35357391f9 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/capture-func-passed-to-jsx.js @@ -0,0 +1,11 @@ +function component(a, b) { + let y = { b }; + let z = { a }; + let x = function () { + z.a = 2; + y.b; + }; + let t = ; + mutate(x); // x should be frozen here + return t; +}