[test] Add test for capturing a renamed ref
The ref isn't renamed inside the lambda, needs to be fixed.
Sathya Gunasekaran committed
Mar 8, 2023 at 00:15 UTC
80ab2f25a64898e81429611586bd89bf187f5876
2 files changed
+60
compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-function-renamed-ref.expect.md
new
+50
@@ -0,0 +1,50 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function component(a, b) {
6
+ let z = { a };
7
+ {
8
+ let z = { b };
9
+ (function () {
10
+ mutate(z);
11
+ })();
12
+ }
13
+ return z;
14
+}
15
+
16
+```
17
+
18
+## Code
19
+
20
+```javascript
21
+function component(a, b) {
22
+ const $ = React.unstable_useMemoCache(4);
23
+ const c_0 = $[0] !== a;
24
+ let t0;
25
+ if (c_0) {
26
+ t0 = { a };
27
+ $[0] = a;
28
+ $[1] = t0;
29
+ } else {
30
+ t0 = $[1];
31
+ }
32
+ const z = t0;
33
+ const c_2 = $[2] !== b;
34
+ let t1;
35
+ if (c_2) {
36
+ t1 = { b };
37
+ $[2] = b;
38
+ $[3] = t1;
39
+ } else {
40
+ t1 = $[3];
41
+ }
42
+ const z_0 = t1;
43
+ (function () {
44
+ mutate(z);
45
+ })();
46
+ return z;
47
+}
48
+
49
+```
50
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-function-renamed-ref.js
new
+10
@@ -0,0 +1,10 @@
1
+function component(a, b) {
2
+ let z = { a };
3
+ {
4
+ let z = { b };
5
+ (function () {
6
+ mutate(z);
7
+ })();
8
+ }
9
+ return z;
10
+}