[tests] failing tests for dependencies and codegen (#1414)

This commit is contained in:
mofeiZ
2023-03-24 15:23:42 -04:00
parent 0ee5e482a2
commit 568048af0f
4 changed files with 79 additions and 0 deletions
@@ -0,0 +1,31 @@
## Input
```javascript
function Component(props) {
let x = foo(props.a?.b.c.d);
return x;
}
```
## Code
```javascript
function Component(props) {
const $ = React.unstable_useMemoCache(2);
const c_0 = $[0] !== props.a.b.c.d;
let t0;
if (c_0) {
t0 = foo(props.a?.b?.c?.d);
$[0] = props.a.b.c.d;
$[1] = t0;
} else {
t0 = $[1];
}
const x = t0;
return x;
}
```
@@ -0,0 +1,4 @@
function Component(props) {
let x = foo(props.a?.b.c.d);
return x;
}
@@ -0,0 +1,35 @@
## Input
```javascript
function Component(props) {
let a = foo();
// freeze `a` so we know the next line cannot mutate it
<div>{a}</div>;
// b should be dependent on `props.a`
let b = bar(a[props.a] + 1);
return b;
}
```
## Code
```javascript
function Component(props) {
const $ = React.unstable_useMemoCache(1);
const a = foo();
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = bar(a[props.a] + 1);
$[0] = t0;
} else {
t0 = $[0];
}
const b = t0;
return b;
}
```
@@ -0,0 +1,9 @@
function Component(props) {
let a = foo();
// freeze `a` so we know the next line cannot mutate it
<div>{a}</div>;
// b should be dependent on `props.a`
let b = bar(a[props.a] + 1);
return b;
}