From 1da6f456b719e7cb179d8401666862d98b59fdb0 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 3 May 2026 00:36:56 +0000 Subject: [PATCH] refactor(core): apply /simplify findings on sub-comp scoping PR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - compositionLoader.ts: drop the redundant inline `Window` cast; the ambient `__hfVariablesByComp?` declaration in runtime/window.d.ts already covers it within the same package. - compositionScoping.test.ts: drop the `__captured: undefined as unknown` initializers — `Record` already permits the key, the init was noise. Reuse + efficiency reviews returned clean. The scoped getVariables's per-call Object.assign({}, scoped) is consistent with the file's existing scoped-utility conventions (gsap proxy returns fresh bound functions per access) and acceptable since the idiomatic usage destructures once at script init. All 44 touched core tests still green. Co-Authored-By: Claude Opus 4.7 (1M context) --- packages/core/src/compiler/compositionScoping.test.ts | 2 -- packages/core/src/runtime/compositionLoader.ts | 7 ++----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/core/src/compiler/compositionScoping.test.ts b/packages/core/src/compiler/compositionScoping.test.ts index 1c01100c0..4c1a0189b 100644 --- a/packages/core/src/compiler/compositionScoping.test.ts +++ b/packages/core/src/compiler/compositionScoping.test.ts @@ -64,7 +64,6 @@ body { margin: 0; } getVariables: () => ({ title: "TOP-LEVEL-LEAK" }), fitTextFontSize: () => undefined, }, - __captured: undefined as unknown, }; const wrapped = wrapScopedCompositionScript( `window.__captured = __hyperframes.getVariables();`, @@ -85,7 +84,6 @@ body { margin: 0; } getVariables: () => ({ title: "TOP-LEVEL-LEAK" }), fitTextFontSize: () => undefined, }, - __captured: undefined as unknown, }; const wrapped = wrapScopedCompositionScript( `window.__captured = __hyperframes.getVariables();`, diff --git a/packages/core/src/runtime/compositionLoader.ts b/packages/core/src/runtime/compositionLoader.ts index 6c87119a7..f69d6fa39 100644 --- a/packages/core/src/runtime/compositionLoader.ts +++ b/packages/core/src/runtime/compositionLoader.ts @@ -244,11 +244,8 @@ async function mountCompositionContent(params: { ...parseHostVariableValues(params.host), }; if (Object.keys(merged).length > 0) { - const w = window as Window & { - __hfVariablesByComp?: Record>; - }; - if (!w.__hfVariablesByComp) w.__hfVariablesByComp = {}; - w.__hfVariablesByComp[scopeCompositionId] = merged; + if (!window.__hfVariablesByComp) window.__hfVariablesByComp = {}; + window.__hfVariablesByComp[scopeCompositionId] = merged; } }