From 41e8088e8c20b07d4e0a96fb9066839196efaeca Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Thu, 26 Jan 2023 16:40:07 -0500 Subject: [PATCH] [hir] Try to resolve a dep into a property load only if it's a temporary. --- .../src/ReactiveScopes/PropagateScopeDependencies.ts | 8 ++++++-- ...ect-pattern.expect.md => bug_object-pattern.expect.md} | 4 ++-- .../hir/{_bug_object-pattern.js => bug_object-pattern.js} | 0 3 files changed, 8 insertions(+), 4 deletions(-) rename compiler/forget/src/__tests__/fixtures/hir/{_bug_object-pattern.expect.md => bug_object-pattern.expect.md} (87%) rename compiler/forget/src/__tests__/fixtures/hir/{_bug_object-pattern.js => bug_object-pattern.js} (100%) diff --git a/compiler/forget/src/ReactiveScopes/PropagateScopeDependencies.ts b/compiler/forget/src/ReactiveScopes/PropagateScopeDependencies.ts index cb392edf37..7c7de061f1 100644 --- a/compiler/forget/src/ReactiveScopes/PropagateScopeDependencies.ts +++ b/compiler/forget/src/ReactiveScopes/PropagateScopeDependencies.ts @@ -110,8 +110,12 @@ class Context { } else { // Otherwise if this operand is a temporary created for a property load, resolve it to // the expanded Place. Fall back to using the operand as-is. - maybeDependency = - this.#properties.get(dependency.place.identifier) ?? dependency; + let propDep = this.#properties.get(dependency.place.identifier); + if (dependency.place.identifier.name === null && propDep !== undefined) { + maybeDependency = propDep; + } else { + maybeDependency = dependency; + } } const decl = this.#declarations.get(maybeDependency.place.identifier); diff --git a/compiler/forget/src/__tests__/fixtures/hir/_bug_object-pattern.expect.md b/compiler/forget/src/__tests__/fixtures/hir/bug_object-pattern.expect.md similarity index 87% rename from compiler/forget/src/__tests__/fixtures/hir/_bug_object-pattern.expect.md rename to compiler/forget/src/__tests__/fixtures/hir/bug_object-pattern.expect.md index bd9dd995a9..9bb8c235f2 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/_bug_object-pattern.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/bug_object-pattern.expect.md @@ -16,11 +16,11 @@ function component(t) { function component(t) { const $ = React.useMemoCache(); const a = t.a; - const c_0 = $[0] !== t6.a; + const c_0 = $[0] !== a; let y; if (c_0) { y = { a: a }; - $[0] = t6.a; + $[0] = a; $[1] = y; } else { y = $[1]; diff --git a/compiler/forget/src/__tests__/fixtures/hir/_bug_object-pattern.js b/compiler/forget/src/__tests__/fixtures/hir/bug_object-pattern.js similarity index 100% rename from compiler/forget/src/__tests__/fixtures/hir/_bug_object-pattern.js rename to compiler/forget/src/__tests__/fixtures/hir/bug_object-pattern.js