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:
Sathya Gunasekaran
2023-06-20 14:58:36 +01:00
parent 2ca614cb4f
commit 0897cc8a0f
2 changed files with 50 additions and 0 deletions
@@ -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;
}
```
@@ -0,0 +1,9 @@
function App({ text, hasDeps }) {
const resolvedText = useMemo(
() => {
return text.toUpperCase();
},
hasDeps ? null : [text] // should be DCE'd
);
return resolvedText;
}