From 7277897405cc36b9832dc9b9055aec871197f4fe Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Fri, 10 Feb 2023 17:59:59 +0000 Subject: [PATCH] [test] Add test for broken lambda capturing SSA redefines context refs which breaks our inference. The correct fix here is to not overwrite context refs in EnterSSA. --- ..._bug.capturing-func-simple-alias.expect.md | 40 +++++++++++++++++++ .../hir/_bug.capturing-func-simple-alias.js | 9 +++++ 2 files changed, 49 insertions(+) create mode 100644 compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-func-simple-alias.expect.md create mode 100644 compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-func-simple-alias.js diff --git a/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-func-simple-alias.expect.md b/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-func-simple-alias.expect.md new file mode 100644 index 0000000000..cdd4de6e59 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-func-simple-alias.expect.md @@ -0,0 +1,40 @@ + +## Input + +```javascript +function component(a) { + let x = { a }; + let y; + (function () { + y = x; + })(); + mutate(y); + return y; +} + +``` + +## Code + +```javascript +function component(a) { + const $ = React.unstable_useMemoCache(); + const c_0 = $[0] !== a; + let x; + if (c_0) { + x = { a: a }; + $[0] = a; + $[1] = x; + } else { + x = $[1]; + } + const y = undefined; + (function () { + y = x; + })(); + mutate(y); + return y; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-func-simple-alias.js b/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-func-simple-alias.js new file mode 100644 index 0000000000..513bc83336 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-func-simple-alias.js @@ -0,0 +1,9 @@ +function component(a) { + let x = { a }; + let y; + (function () { + y = x; + })(); + mutate(y); + return y; +}