[hir] Check if callee before pruning member path

This commit is contained in:
Sathya Gunasekaran
2023-03-31 16:36:04 +01:00
parent 46a9d40914
commit 3b3d15eaeb
3 changed files with 53 additions and 1 deletions
+4 -1
View File
@@ -2488,7 +2488,10 @@ function gatherCapturedDeps(
if (path.isMemberExpression()) {
// For CallExpression, we need to depend on the receiver, not the
// function itself.
if (path.parent.type === "CallExpression") {
if (
path.parent.type === "CallExpression" &&
path.parent.callee === path.node
) {
path = path.get("object");
}
@@ -0,0 +1,39 @@
## Input
```javascript
function Foo(props) {
const onFoo = useCallback(
(reason) => {
log(props.router.location);
},
[props.router.location]
);
return onFoo;
}
```
## Code
```javascript
function Foo(props) {
const $ = React.unstable_useMemoCache(2);
const c_0 = $[0] !== props.router.location;
let t0;
if (c_0) {
t0 = (reason) => {
log(props.router.location);
};
$[0] = props.router.location;
$[1] = t0;
} else {
t0 = $[1];
}
const onFoo = t0;
return onFoo;
}
```
@@ -0,0 +1,10 @@
function Foo(props) {
const onFoo = useCallback(
(reason) => {
log(props.router.location);
},
[props.router.location]
);
return onFoo;
}