Skip to content

Commit e73b2d1

Browse files
committed
feat: Nil top-level original scopes use an empty tag now
1 parent 70bdccd commit e73b2d1

File tree

4 files changed

+7
-13
lines changed

4 files changed

+7
-13
lines changed

src/codec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
export const enum Tag {
6+
EMPTY = 0x0,
67
ORIGINAL_SCOPE_START = 0x1,
78
ORIGINAL_SCOPE_END = 0x2,
89
ORIGINAL_SCOPE_VARIABLES = 0x3,
@@ -14,6 +15,7 @@ export const enum Tag {
1415
}
1516

1617
export const enum EncodedTag {
18+
EMPTY = "A", // 0x0
1719
ORIGINAL_SCOPE_START = "B", // 0x1
1820
ORIGINAL_SCOPE_END = "C", // 0x2
1921
ORIGINAL_SCOPE_VARIABLES = "D", // 0x3

src/decode/decode.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,11 @@ class Decoder {
141141
const iter = new TokenIterator(this.#encodedScopes);
142142

143143
while (iter.hasNext()) {
144-
if (iter.peek() === ",") {
145-
iter.nextChar(); // Consume ",".
146-
this.#scopes.push(null); // Add an EmptyItem;
147-
continue;
148-
}
149-
150144
const tag = iter.nextUnsignedVLQ();
151145
switch (tag) {
146+
case Tag.EMPTY:
147+
this.#scopes.push(null);
148+
break;
152149
case Tag.ORIGINAL_SCOPE_START: {
153150
const item: OriginalScopeStartItem = {
154151
flags: iter.nextUnsignedVLQ(),
@@ -255,11 +252,6 @@ class Decoder {
255252
if (iter.hasNext()) iter.nextChar();
256253
}
257254

258-
if (iter.currentChar() === ",") {
259-
// Handle trailing EmptyItem.
260-
this.#scopes.push(null);
261-
}
262-
263255
if (this.#scopeStack.length > 0) {
264256
this.#throwInStrictMode(
265257
"Encountered ORIGINAL_SCOPE_START without matching END!",

src/encode/encode.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe("encode", () => {
4848
it("encodes null OriginalScopes correctly", () => {
4949
const info = builder.addNullScope().addNullScope().addNullScope().build();
5050

51-
assertStrictEquals(encode(info).scopes, ",,");
51+
assertStrictEquals(encode(info).scopes, "A,A,A");
5252
});
5353

5454
it("throws when a child scope' start is not nested properly within its parent", () => {

src/encode/encoder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class Encoder {
6666

6767
#encodeOriginalScope(scope: OriginalScope | null): void {
6868
if (scope === null) {
69-
this.#encodedItems.push("");
69+
this.#encodedItems.push(EncodedTag.EMPTY);
7070
return;
7171
}
7272

0 commit comments

Comments
 (0)