@samitouri / QOS-React-2 / commits / 3b3d15eaeb

[hir] Check if callee before pruning member path

Sathya Gunasekaran committed Mar 31, 2023 at 16:36 UTC 3b3d15eaeb70814a096dba5d87b87c3ee7241cf7
3 files changed +53 -1
compiler/forget/src/HIR/BuildHIR.ts
+4 -1
@@ -2488,7 +2488,10 @@ function gatherCapturedDeps(
2488 if (path.isMemberExpression()) {
2489 // For CallExpression, we need to depend on the receiver, not the
2490 // function itself.
2491 - if (path.parent.type === "CallExpression") {
2491 + if (
2492 + path.parent.type === "CallExpression" &&
2493 + path.parent.callee === path.node
2494 + ) {
2495 path = path.get("object");
2496 }
2497
compiler/forget/src/__tests__/fixtures/compiler/capturing-function-member-expr-arguments.expect.md new
+39
@@ -0,0 +1,39 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function Foo(props) {
6 + const onFoo = useCallback(
7 + (reason) => {
8 + log(props.router.location);
9 + },
10 + [props.router.location]
11 + );
12 +
13 + return onFoo;
14 +}
15 +
16 +```
17 +
18 +## Code
19 +
20 +```javascript
21 +function Foo(props) {
22 + const $ = React.unstable_useMemoCache(2);
23 + const c_0 = $[0] !== props.router.location;
24 + let t0;
25 + if (c_0) {
26 + t0 = (reason) => {
27 + log(props.router.location);
28 + };
29 + $[0] = props.router.location;
30 + $[1] = t0;
31 + } else {
32 + t0 = $[1];
33 + }
34 + const onFoo = t0;
35 + return onFoo;
36 +}
37 +
38 +```
39 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/capturing-function-member-expr-arguments.js new
+10
@@ -0,0 +1,10 @@
1 +function Foo(props) {
2 + const onFoo = useCallback(
3 + (reason) => {
4 + log(props.router.location);
5 + },
6 + [props.router.location]
7 + );
8 +
9 + return onFoo;
10 +}