[test] Add test for lambda that conditionally captures ref

Conditionally captured refs are correctly added to dependency list of the 
lambda.
This commit is contained in:
Sathya Gunasekaran
2023-03-08 00:15:51 +00:00
parent 1e8b6b51d3
commit d155d2dd81
2 changed files with 64 additions and 0 deletions
@@ -0,0 +1,54 @@
## Input
```javascript
function component(a, b) {
let z = { a };
let y = b;
let x = function () {
if (y) {
mutate(z);
}
};
return x;
}
```
## Code
```javascript
function component(a, b) {
const $ = React.unstable_useMemoCache(5);
const c_0 = $[0] !== a;
let t0;
if (c_0) {
t0 = { a };
$[0] = a;
$[1] = t0;
} else {
t0 = $[1];
}
const z = t0;
const y = b;
const c_2 = $[2] !== y;
const c_3 = $[3] !== z;
let t1;
if (c_2 || c_3) {
t1 = function () {
if (y) {
mutate(z);
}
};
$[2] = y;
$[3] = z;
$[4] = t1;
} else {
t1 = $[4];
}
const x = t1;
return x;
}
```
@@ -0,0 +1,10 @@
function component(a, b) {
let z = { a };
let y = b;
let x = function () {
if (y) {
mutate(z);
}
};
return x;
}