mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Add failing test for DropMemoCalls failing to DCE dep array
Found this while running Forget on the React tests. This isn't a high priority because the ESLint plugin would've caught this. But it'd be nice if either our validation rules caught this or if our compiler did correctly eliminate the dep array.
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function App({text, hasDeps}) {
|
||||
const resolvedText = useMemo(
|
||||
() => {
|
||||
return text.toUpperCase();
|
||||
},
|
||||
hasDeps ? null : [text], // should be DCE'd
|
||||
);
|
||||
return resolvedText;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
function App(t26) {
|
||||
const $ = useMemoCache(2);
|
||||
const { text, hasDeps } = t26;
|
||||
|
||||
hasDeps ? null : [text];
|
||||
const c_0 = $[0] !== text;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = text.toUpperCase();
|
||||
$[0] = text;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
t0 = $[1];
|
||||
}
|
||||
const t19 = t0;
|
||||
const resolvedText = t19;
|
||||
return resolvedText;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
function App({ text, hasDeps }) {
|
||||
const resolvedText = useMemo(
|
||||
() => {
|
||||
return text.toUpperCase();
|
||||
},
|
||||
hasDeps ? null : [text] // should be DCE'd
|
||||
);
|
||||
return resolvedText;
|
||||
}
|
||||
Reference in New Issue
Block a user