@samitouri / QOS-React-2 / commits / 8695ea05c3

[test] Add test for capturing a ref before renaming

The renaming does not affect the lambda correctly.

Sathya Gunasekaran committed Mar 8, 2023 at 00:15 UTC 8695ea05c3e8a0112c7cabcf1b7003b024776b85
2 files changed +80
compiler/forget/src/__tests__/fixtures/hir/capturing-function-capture-ref-before-rename.expect.md new
+66
@@ -0,0 +1,66 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function component(a, b) {
6 + let z = { a };
7 + (function () {
8 + mutate(z);
9 + })();
10 + let y = z;
11 +
12 + {
13 + // z is shadowed & renamed but the lambda is unaffected.
14 + let z = { b };
15 + y = { y, z };
16 + }
17 + return y;
18 +}
19 +
20 +```
21 +
22 +## Code
23 +
24 +```javascript
25 +function component(a, b) {
26 + const $ = React.unstable_useMemoCache(7);
27 + const c_0 = $[0] !== a;
28 + let z;
29 + if (c_0) {
30 + z = { a };
31 + (function () {
32 + mutate(z);
33 + })();
34 + $[0] = a;
35 + $[1] = z;
36 + } else {
37 + z = $[1];
38 + }
39 + let y = z;
40 + const c_2 = $[2] !== b;
41 + let t0;
42 + if (c_2) {
43 + t0 = { b };
44 + $[2] = b;
45 + $[3] = t0;
46 + } else {
47 + t0 = $[3];
48 + }
49 + const z_0 = t0;
50 + const c_4 = $[4] !== y;
51 + const c_5 = $[5] !== z_0;
52 + let t1;
53 + if (c_4 || c_5) {
54 + t1 = { y, z: z_0 };
55 + $[4] = y;
56 + $[5] = z_0;
57 + $[6] = t1;
58 + } else {
59 + t1 = $[6];
60 + }
61 + y = t1;
62 + return y;
63 +}
64 +
65 +```
66 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/capturing-function-capture-ref-before-rename.js new
+14
@@ -0,0 +1,14 @@
1 +function component(a, b) {
2 + let z = { a };
3 + (function () {
4 + mutate(z);
5 + })();
6 + let y = z;
7 +
8 + {
9 + // z is shadowed & renamed but the lambda is unaffected.
10 + let z = { b };
11 + y = { y, z };
12 + }
13 + return y;
14 +}