From 287e751f2b8618acc90ef6611210b4f2d871ef41 Mon Sep 17 00:00:00 2001 From: Gunjan Jaswal Date: Sun, 5 Jul 2026 04:08:59 +0530 Subject: [PATCH 1/2] Reset keyToScope and lastScope in ScopeInfoBuilder.build() --- src/builder/builder.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/builder/builder.ts b/src/builder/builder.ts index cd25b94..4647194 100644 --- a/src/builder/builder.ts +++ b/src/builder/builder.ts @@ -228,6 +228,8 @@ export class ScopeInfoBuilder { this.#scopes = []; this.#ranges = []; this.#knownScopes.clear(); + this.#keyToScope.clear(); + this.#lastScope = null; return info; } From a7118be8e06137c5f409befb643b2b9d9d6b0956 Mon Sep 17 00:00:00 2001 From: Gunjan Jaswal Date: Sun, 5 Jul 2026 04:09:01 +0530 Subject: [PATCH 2/2] Add test for builder state reset across build() calls --- src/builder/builder.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/builder/builder.test.ts b/src/builder/builder.test.ts index 3c6f1e4..d0ccd43 100644 --- a/src/builder/builder.test.ts +++ b/src/builder/builder.test.ts @@ -368,4 +368,20 @@ describe("ScopeInfoBuilder", () => { assertStrictEquals(info.ranges[0].originalScope, info.scopes[0]); }); }); + + describe("build", () => { + it("resets accumulated state so a reused builder does not leak across builds", () => { + builder.startScope(0, 0, { key: 0 }).endScope(10, 0); + builder.startRange(0, 0, { scopeKey: 0 }).endRange(0, 10); + builder.build(); + + // Key 0 is not registered in this second build, so the range must not + // resolve to a scope carried over from the previous build. + const info = builder.startRange(0, 0, { scopeKey: 0 }).endRange(0, 10) + .build(); + + assertStrictEquals(info.ranges[0].originalScope, undefined); + assertStrictEquals(builder.lastScope(), null); + }); + }); });