More useMemo inlining test cases

More test cases for useMemo inlining, including the problematic case we found 
internally and some similar tricky cases with labels.
This commit is contained in:
Joe Savona
2023-05-17 15:55:52 -07:00
parent 329809de81
commit f30041b0f0
6 changed files with 160 additions and 0 deletions
@@ -0,0 +1,37 @@
## Input
```javascript
function Component(props) {
const x = useMemo(() => {
label: {
if (props.cond) {
break label;
}
return props.a;
}
return props.b;
});
return x;
}
```
## Code
```javascript
function Component(props) {
let t17 = undefined;
bb10: {
if (props.cond) {
t17 = props.b;
break bb10;
}
t17 = props.a;
}
const x = t17;
return x;
}
```
@@ -0,0 +1,12 @@
function Component(props) {
const x = useMemo(() => {
label: {
if (props.cond) {
break label;
}
return props.a;
}
return props.b;
});
return x;
}
@@ -0,0 +1,28 @@
## Input
```javascript
function Component(props) {
const x = useMemo(() => {
if (props.cond) {
if (props.cond) {
}
}
}, [props.cond]);
return x;
}
```
## Code
```javascript
function Component(props) {
if (props.cond) {
if (props.cond) {
}
}
}
```
@@ -0,0 +1,9 @@
function Component(props) {
const x = useMemo(() => {
if (props.cond) {
if (props.cond) {
}
}
}, [props.cond]);
return x;
}
@@ -0,0 +1,55 @@
## Input
```javascript
function Component(props) {
const x = useMemo(() => {
let y;
switch (props.switch) {
case "foo": {
return "foo";
}
case "bar": {
y = "bar";
break;
}
default: {
y = props.y;
}
}
return y;
});
return x;
}
```
## Code
```javascript
function Component(props) {
let t22 = undefined;
bb10: {
let y = undefined;
bb2: switch (props.switch) {
case "foo": {
t22 = "foo";
break bb10;
}
case "bar": {
y = "bar";
break bb2;
}
default: {
y = props.y;
}
}
t22 = y;
}
const x = t22;
return x;
}
```
@@ -0,0 +1,19 @@
function Component(props) {
const x = useMemo(() => {
let y;
switch (props.switch) {
case "foo": {
return "foo";
}
case "bar": {
y = "bar";
break;
}
default: {
y = props.y;
}
}
return y;
});
return x;
}