Add new test cases for SSA

Add these as a separate commit so we can see how later PRs in the stack change 
them
This commit is contained in:
Lauren Tan
2023-02-08 10:26:26 -05:00
parent 5888cbdd9b
commit 1809ffd06d
6 changed files with 220 additions and 0 deletions
@@ -0,0 +1,68 @@
## Input
```javascript
function Component(props) {
let x = [];
let y;
if (props.p0) {
x.push(props.p1);
y = x;
}
return (
<Component>
{x}
{y}
</Component>
);
}
```
## Code
```javascript
function Component(props) {
const $ = React.unstable_useMemoCache();
const c_0 = $[0] !== props.p0;
const c_1 = $[1] !== props.p1;
let x;
let y$0;
if (c_0 || c_1) {
x = [];
const y = undefined;
y$0 = y;
if (props.p0) {
x.push(props.p1);
const y$1 = x;
y$0 = y$1;
}
$[0] = props.p0;
$[1] = props.p1;
$[2] = x;
$[3] = y$0;
} else {
x = $[2];
y$0 = $[3];
}
const c_4 = $[4] !== x;
const c_5 = $[5] !== y$0;
let t0;
if (c_4 || c_5) {
t0 = (
<Component>
{x}
{y$0}
</Component>
);
$[4] = x;
$[5] = y$0;
$[6] = t0;
} else {
t0 = $[6];
}
return t0;
}
```
@@ -0,0 +1,14 @@
function Component(props) {
let x = [];
let y;
if (props.p0) {
x.push(props.p1);
y = x;
}
return (
<Component>
{x}
{y}
</Component>
);
}
@@ -0,0 +1,56 @@
## Input
```javascript
function foo(props) {
let x = [];
x.push(props.bar);
if (props.cond) {
x = {};
x = [];
x.push(props.foo);
}
mut(x);
return x;
}
```
## Code
```javascript
function foo(props) {
const $ = React.unstable_useMemoCache();
const c_0 = $[0] !== props.bar;
let x;
if (c_0) {
x = [];
x.push(props.bar);
$[0] = props.bar;
$[1] = x;
} else {
x = $[1];
}
const c_2 = $[2] !== props.cond;
const c_3 = $[3] !== props.foo;
let x$0;
if (c_2 || c_3) {
x$0 = x;
if (props.cond) {
const x$1 = [];
x$1.push(props.foo);
x$0 = x$1;
}
mut(x$0);
$[2] = props.cond;
$[3] = props.foo;
$[4] = x$0;
} else {
x$0 = $[4];
}
return x$0;
}
```
@@ -0,0 +1,11 @@
function foo(props) {
let x = [];
x.push(props.bar);
if (props.cond) {
x = {};
x = [];
x.push(props.foo);
}
mut(x);
return x;
}
@@ -0,0 +1,61 @@
## Input
```javascript
function foo(props) {
let x = [];
x.push(props.bar);
if (props.cond) {
x = {};
x = [];
x.push(props.foo);
}
return x;
}
```
## Code
```javascript
function foo(props) {
const $ = React.unstable_useMemoCache();
const c_0 = $[0] !== props.bar;
let x;
if (c_0) {
x = [];
x.push(props.bar);
$[0] = props.bar;
$[1] = x;
} else {
x = $[1];
}
const c_2 = $[2] !== props.cond;
const c_3 = $[3] !== props.foo;
let x$0;
if (c_2 || c_3) {
x$0 = x;
if (props.cond) {
const c_5 = $[5] !== props.foo;
let x$1;
if (c_5) {
x$1 = [];
x$1.push(props.foo);
$[5] = props.foo;
$[6] = x$1;
} else {
x$1 = $[6];
}
x$0 = x$1;
}
$[2] = props.cond;
$[3] = props.foo;
$[4] = x$0;
} else {
x$0 = $[4];
}
return x$0;
}
```
@@ -0,0 +1,10 @@
function foo(props) {
let x = [];
x.push(props.bar);
if (props.cond) {
x = {};
x = [];
x.push(props.foo);
}
return x;
}