From 80ab2f25a64898e81429611586bd89bf187f5876 Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Wed, 8 Mar 2023 00:15:54 +0000 Subject: [PATCH] [test] Add test for capturing a renamed ref The ref isn't renamed inside the lambda, needs to be fixed. --- ...g.capturing-function-renamed-ref.expect.md | 50 +++++++++++++++++++ .../_bug.capturing-function-renamed-ref.js | 10 ++++ 2 files changed, 60 insertions(+) create mode 100644 compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-function-renamed-ref.expect.md create mode 100644 compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-function-renamed-ref.js diff --git a/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-function-renamed-ref.expect.md b/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-function-renamed-ref.expect.md new file mode 100644 index 0000000000..736833c494 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-function-renamed-ref.expect.md @@ -0,0 +1,50 @@ + +## Input + +```javascript +function component(a, b) { + let z = { a }; + { + let z = { b }; + (function () { + mutate(z); + })(); + } + return z; +} + +``` + +## Code + +```javascript +function component(a, b) { + const $ = React.unstable_useMemoCache(4); + const c_0 = $[0] !== a; + let t0; + if (c_0) { + t0 = { a }; + $[0] = a; + $[1] = t0; + } else { + t0 = $[1]; + } + const z = t0; + const c_2 = $[2] !== b; + let t1; + if (c_2) { + t1 = { b }; + $[2] = b; + $[3] = t1; + } else { + t1 = $[3]; + } + const z_0 = t1; + (function () { + mutate(z); + })(); + return z; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-function-renamed-ref.js b/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-function-renamed-ref.js new file mode 100644 index 0000000000..5ad8300381 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-function-renamed-ref.js @@ -0,0 +1,10 @@ +function component(a, b) { + let z = { a }; + { + let z = { b }; + (function () { + mutate(z); + })(); + } + return z; +}