Skip to content

Commit d1f5080

Browse files
committed
Only reset line/column decoding state for top-level scopes
Last bit to align with tc39/ecma426#188.
1 parent ae534f7 commit d1f5080

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/decode/decode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ class Decoder {
287287
parent.children.push(scope);
288288
} else {
289289
this.#scopes.push(scope);
290-
Object.assign(this.#scopeState, DEFAULT_SCOPE_STATE);
290+
this.#scopeState.line = 0;
291+
this.#scopeState.column = 0;
291292
}
292293
}
293294

src/encode/encoder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export class Encoder {
5252
encode(): string {
5353
this.#encodedItems = [];
5454
this.#info.scopes.forEach((scope) => {
55-
Object.assign(this.#scopeState, DEFAULT_SCOPE_STATE);
55+
this.#scopeState.line = 0;
56+
this.#scopeState.column = 0;
5657
this.#encodeOriginalScope(scope);
5758
});
5859
this.#info.ranges.forEach((range) => {

src/roundtrip.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ describe("round trip", () => {
7878
assertCodec(builder.build());
7979
});
8080

81+
it("handles names/kinds across multiple top-level scopes", () => {
82+
builder.startScope(0, 0, { kind: "Global" }).startScope(10, 5, {
83+
kind: "Function",
84+
name: "foo",
85+
})
86+
.endScope(20, 0).endScope(30, 0);
87+
builder.startScope(0, 0, { kind: "Global" }).startScope(10, 5, {
88+
kind: "Function",
89+
name: "bar",
90+
})
91+
.endScope(20, 0).endScope(30, 0);
92+
93+
assertCodec(builder.build());
94+
});
95+
8196
it("handles isStackFrame flag on scopes", () => {
8297
builder.startScope(0, 0, { isStackFrame: true }).endScope(10, 0);
8398

0 commit comments

Comments
 (0)