@samitouri / QOS-React-2 / commits / d155d2dd81

[test] Add test for lambda that conditionally captures ref

Conditionally captured refs are correctly added to dependency list of the lambda.

Sathya Gunasekaran committed Mar 8, 2023 at 00:15 UTC d155d2dd81a70985166ff4ee09217cde8a2f9ad5
2 files changed +64
compiler/forget/src/__tests__/fixtures/hir/capturing-function-conditional-capture-mutate.expect.md new
+54
@@ -0,0 +1,54 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function component(a, b) {
6 + let z = { a };
7 + let y = b;
8 + let x = function () {
9 + if (y) {
10 + mutate(z);
11 + }
12 + };
13 + return x;
14 +}
15 +
16 +```
17 +
18 +## Code
19 +
20 +```javascript
21 +function component(a, b) {
22 + const $ = React.unstable_useMemoCache(5);
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 y = b;
34 + const c_2 = $[2] !== y;
35 + const c_3 = $[3] !== z;
36 + let t1;
37 + if (c_2 || c_3) {
38 + t1 = function () {
39 + if (y) {
40 + mutate(z);
41 + }
42 + };
43 + $[2] = y;
44 + $[3] = z;
45 + $[4] = t1;
46 + } else {
47 + t1 = $[4];
48 + }
49 + const x = t1;
50 + return x;
51 +}
52 +
53 +```
54 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/capturing-function-conditional-capture-mutate.js new
+10
@@ -0,0 +1,10 @@
1 +function component(a, b) {
2 + let z = { a };
3 + let y = b;
4 + let x = function () {
5 + if (y) {
6 + mutate(z);
7 + }
8 + };
9 + return x;
10 +}