@samitouri / QOS-React-2 / commits / 19dd29707b

[λ] Fix mutatedDep collection in AnalyseFunctions

Make sure to check free variables as well for mutations. Not just object properties.

Sathya Gunasekaran committed Jan 23, 2023 at 15:46 UTC 19dd29707b5f4e3457588336a211e282cba1c39b
2 files changed +13 -6
compiler/forget/src/Inference/AnalyseFunctions.ts
+5
@@ -85,6 +85,11 @@ function buildMutatedDeps(
85 continue;
86 }
87
88 + mutatedDeps.push(dep);
89 + } else if (
90 + dep.identifier.name !== null &&
91 + mutatedIds.has(dep.identifier.name)
92 + ) {
93 mutatedDeps.push(dep);
94 }
95 }
compiler/forget/src/__tests__/fixtures/hir/mutate-captured-arg-separately.expect.md
+8 -6
@@ -19,18 +19,20 @@ function component(a) {
19 ```javascript
20 function component(a) {
21 const $ = React.useMemoCache();
22 + const c_0 = $[0] !== a;
23 let y;
23 - if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
24 + if (c_0) {
25 y = function () {
26 m(x);
27 };
27 - $[0] = y;
28 +
29 + const x = { a: a };
30 + m(x);
31 + $[0] = a;
32 + $[1] = y;
33 } else {
29 - y = $[0];
34 + y = $[1];
35 }
31 -
32 - const x = { a: a };
33 - m(x);
36 return y;
37 }
38