mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user