@samitouri / QOS-React / commits / 7277897405

[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.

Sathya Gunasekaran committed Feb 10, 2023 at 17:59 UTC 7277897405cc36b9832dc9b9055aec871197f4fe
2 files changed +49
compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-func-simple-alias.expect.md new
+40
@@ -0,0 +1,40 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function component(a) {
6 + let x = { a };
7 + let y;
8 + (function () {
9 + y = x;
10 + })();
11 + mutate(y);
12 + return y;
13 +}
14 +
15 +```
16 +
17 +## Code
18 +
19 +```javascript
20 +function component(a) {
21 + const $ = React.unstable_useMemoCache();
22 + const c_0 = $[0] !== a;
23 + let x;
24 + if (c_0) {
25 + x = { a: a };
26 + $[0] = a;
27 + $[1] = x;
28 + } else {
29 + x = $[1];
30 + }
31 + const y = undefined;
32 + (function () {
33 + y = x;
34 + })();
35 + mutate(y);
36 + return y;
37 +}
38 +
39 +```
40 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-func-simple-alias.js new
+9
@@ -0,0 +1,9 @@
1 +function component(a) {
2 + let x = { a };
3 + let y;
4 + (function () {
5 + y = x;
6 + })();
7 + mutate(y);
8 + return y;
9 +}