From 19dd29707b5f4e3457588336a211e282cba1c39b Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Mon, 23 Jan 2023 15:46:35 -0500 Subject: [PATCH] =?UTF-8?q?[=CE=BB]=20Fix=20mutatedDep=20collection=20in?= =?UTF-8?q?=20AnalyseFunctions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure to check free variables as well for mutations. Not just object properties. --- .../forget/src/Inference/AnalyseFunctions.ts | 5 +++++ .../hir/mutate-captured-arg-separately.expect.md | 16 +++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/compiler/forget/src/Inference/AnalyseFunctions.ts b/compiler/forget/src/Inference/AnalyseFunctions.ts index ce245a5a20..93dcf1e6c1 100644 --- a/compiler/forget/src/Inference/AnalyseFunctions.ts +++ b/compiler/forget/src/Inference/AnalyseFunctions.ts @@ -85,6 +85,11 @@ function buildMutatedDeps( continue; } + mutatedDeps.push(dep); + } else if ( + dep.identifier.name !== null && + mutatedIds.has(dep.identifier.name) + ) { mutatedDeps.push(dep); } } diff --git a/compiler/forget/src/__tests__/fixtures/hir/mutate-captured-arg-separately.expect.md b/compiler/forget/src/__tests__/fixtures/hir/mutate-captured-arg-separately.expect.md index 5745524c79..37237ef313 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/mutate-captured-arg-separately.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/mutate-captured-arg-separately.expect.md @@ -19,18 +19,20 @@ function component(a) { ```javascript function component(a) { const $ = React.useMemoCache(); + const c_0 = $[0] !== a; let y; - if ($[0] === Symbol.for("react.memo_cache_sentinel")) { + if (c_0) { y = function () { m(x); }; - $[0] = y; - } else { - y = $[0]; - } - const x = { a: a }; - m(x); + const x = { a: a }; + m(x); + $[0] = a; + $[1] = y; + } else { + y = $[1]; + } return y; }