[λ] Add test for function expr passed to jsx

Function exprs become frozen when captured by jsx.
This commit is contained in:
Sathya Gunasekaran
2023-01-20 19:44:32 +00:00
parent 294b6c752d
commit 123d024af7
2 changed files with 81 additions and 0 deletions
@@ -0,0 +1,70 @@
## Input
```javascript
function component(a, b) {
let y = { b };
let z = { a };
let x = function () {
z.a = 2;
y.b;
};
let t = <Foo x={x}></Foo>;
mutate(x); // x should be frozen here
return t;
}
```
## Code
```javascript
function component(a, b) {
const $ = React.useMemoCache();
const c_0 = $[0] !== b;
let y;
if (c_0) {
y = { b: b };
$[0] = b;
$[1] = y;
} else {
y = $[1];
}
const c_2 = $[2] !== a;
let z;
if (c_2) {
z = { a: a };
$[2] = a;
$[3] = z;
} else {
z = $[3];
}
const c_4 = $[4] !== z.a;
const c_5 = $[5] !== y.b;
let x;
if (c_4 || c_5) {
x = function () {
z.a = 2;
y.b;
};
$[4] = z.a;
$[5] = y.b;
$[6] = x;
} else {
x = $[6];
}
const c_7 = $[7] !== x;
let t;
if (c_7) {
t = <Foo x={x}></Foo>;
$[7] = x;
$[8] = t;
} else {
t = $[8];
}
mutate(x);
return t;
}
```
@@ -0,0 +1,11 @@
function component(a, b) {
let y = { b };
let z = { a };
let x = function () {
z.a = 2;
y.b;
};
let t = <Foo x={x}></Foo>;
mutate(x); // x should be frozen here
return t;
}