[hir] Use receiver of CallExpression as dep

This commit is contained in:
Sathya Gunasekaran
2023-02-15 15:03:29 +00:00
parent 008cebd633
commit 06e5681198
4 changed files with 82 additions and 2 deletions
+6
View File
@@ -1987,6 +1987,12 @@ function gatherCapturedDeps(
return;
}
// For CallExpression, we need to depend on the receiver, not the
// function itself.
if (path.parent.type === "CallExpression" && path.isMemberExpression()) {
path = path.get("object");
}
path.skip();
capturedIds.add(binding.identifier);
capturedRefs.add(lowerExpressionToPlace(builder, path));
@@ -0,0 +1,63 @@
## Input
```javascript
function component({ mutator }) {
const poke = () => {
mutator.poke();
};
const hide = () => {
mutator.user.hide();
};
return <Foo poke={poke} hide={hide}></Foo>;
}
```
## Code
```javascript
function component(t10) {
const $ = React.unstable_useMemoCache();
const t0 = t10;
const mutator = t0.mutator;
const c_0 = $[0] !== mutator;
let poke;
if (c_0) {
poke = () => {
mutator.poke();
};
$[0] = mutator;
$[1] = poke;
} else {
poke = $[1];
}
const c_2 = $[2] !== t0.mutator.user;
let hide;
if (c_2) {
hide = () => {
mutator.user.hide();
};
$[2] = t0.mutator.user;
$[3] = hide;
} else {
hide = $[3];
}
const c_4 = $[4] !== poke;
const c_5 = $[5] !== hide;
let t1;
if (c_4 || c_5) {
t1 = <Foo poke={poke} hide={hide}></Foo>;
$[4] = poke;
$[5] = hide;
$[6] = t1;
} else {
t1 = $[6];
}
return t1;
}
```
@@ -0,0 +1,11 @@
function component({ mutator }) {
const poke = () => {
mutator.poke();
};
const hide = () => {
mutator.user.hide();
};
return <Foo poke={poke} hide={hide}></Foo>;
}
@@ -35,13 +35,13 @@ function component(a) {
} else {
z = $[3];
}
const c_4 = $[4] !== z.a.a;
const c_4 = $[4] !== z.a;
let x;
if (c_4) {
x = function () {
z.a.a();
};
$[4] = z.a.a;
$[4] = z.a;
$[5] = x;
} else {
x = $[5];