From 6658f57e12b367830cd5ff1b09578063e46bb874 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli-ai-agent <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 4 Sep 2026 18:53:24 -0400 Subject: [PATCH] Update content-tag to 4.2.0 content-tag 4.0.0 renamed the range fields from start/end to startByte/endByte, and added startChar/endChar. The byte fields keep the previous behavior, so the Buffer slicing in this package is unchanged apart from the field names. content-tag 4.1.0 strips the whitespace and indentation around template contents during process. The unprocess round-trip tests compared line by line and expected the original newlines next to the template tags. The comparison now splits at the template tags so that whitespace at the tag boundaries does not affect the result. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01Fvnp457DHuZC4fBa2KCiqB --- package.json | 2 +- pnpm-lock.yaml | 10 +++++----- src/coordinates-of.js | 4 ++-- src/internal-types.ts | 4 ++-- src/transformer.js | 11 +++++++---- tests/transformer.parseResultAt.test.ts | 8 ++++---- tests/unprocess.test.ts | 9 +++++++-- 7 files changed, 28 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 7b6cfd7..0ebe1ae 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "test": "vitest" }, "dependencies": { - "content-tag": "^3.1.2", + "content-tag": "^4.2.0", "jscodeshift": "^17.2.0" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 71c2459..8fc31e7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: content-tag: - specifier: ^3.1.2 - version: 3.1.2 + specifier: ^4.2.0 + version: 4.2.0 jscodeshift: specifier: ^17.2.0 version: 17.2.0 @@ -851,8 +851,8 @@ packages: config-chain@1.1.13: resolution: {integrity: sha512-qj+f8APARXHrM0hraqXYb2/bOVSV4PvJQlNZ/DVj0QrmNM2q2euizkeuVckQ57J+W0mRH6Hvi+k50M4Jul2VRQ==} - content-tag@3.1.2: - resolution: {integrity: sha512-Z+MGhZfnFFKzYC+pUTWXnoDYhfiXP9ojZe3JbwsYufmDuoeq2EvuDyeFAJ/RnKokUwz5s9bQhDOrbvSYRShcrQ==} + content-tag@4.2.0: + resolution: {integrity: sha512-f/o+F3qSa4gg23I7RWy6cMDxP2nPo99YWusxw2bjne7ZC6Acqqf4uB/+87AekOq1ehTocHH7b7nMd2X4S3NHVw==} convert-source-map@2.0.0: resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==} @@ -2755,7 +2755,7 @@ snapshots: ini: 1.3.8 proto-list: 1.2.4 - content-tag@3.1.2: {} + content-tag@4.2.0: {} convert-source-map@2.0.0: {} diff --git a/src/coordinates-of.js b/src/coordinates-of.js index 231fa51..f125948 100644 --- a/src/coordinates-of.js +++ b/src/coordinates-of.js @@ -24,9 +24,9 @@ export function coordinatesOf(source, parsedResult) { let { contentRange: byteRange } = parsedResult; let inclusiveContent = buffer - .slice(byteRange.start, byteRange.end) + .slice(byteRange.startByte, byteRange.endByte) .toString(); - let beforeContent = buffer.slice(0, byteRange.start).toString(); + let beforeContent = buffer.slice(0, byteRange.startByte).toString(); let before = beforeContent.length; let startCharIndex = before; diff --git a/src/internal-types.ts b/src/internal-types.ts index 3dd1799..aa788af 100644 --- a/src/internal-types.ts +++ b/src/internal-types.ts @@ -7,11 +7,11 @@ export interface ContentRangeResult { /** * The start byte index of the content-range */ - start: number; + startByte: number; /** * The end byte index of the content-range */ - end: number; + endByte: number; }; } diff --git a/src/transformer.js b/src/transformer.js index 7bdd1fc..05ff87e 100644 --- a/src/transformer.js +++ b/src/transformer.js @@ -414,7 +414,7 @@ export class ParseResultStringUtils { * @param {ParseResult} parseResult */ contentBefore(parseResult) { - return this.#buffer.slice(0, parseResult.range.start).toString(); + return this.#buffer.slice(0, parseResult.range.startByte).toString(); } /** @@ -422,7 +422,10 @@ export class ParseResultStringUtils { */ originalContentOf(parseResult) { return this.#buffer - .slice(parseResult.contentRange.start, parseResult.contentRange.end) + .slice( + parseResult.contentRange.startByte, + parseResult.contentRange.endByte, + ) .toString(); } @@ -442,7 +445,7 @@ export class ParseResultStringUtils { */ openingTag(parseResult) { let openingTag = this.#buffer - .slice(parseResult.startRange.start, parseResult.startRange.end) + .slice(parseResult.startRange.startByte, parseResult.startRange.endByte) .toString(); return openingTag; } @@ -452,7 +455,7 @@ export class ParseResultStringUtils { */ closingTag(parseResult) { let closingTag = this.#buffer - .slice(parseResult.endRange.start, parseResult.endRange.end) + .slice(parseResult.endRange.startByte, parseResult.endRange.endByte) .toString(); return closingTag; } diff --git a/tests/transformer.parseResultAt.test.ts b/tests/transformer.parseResultAt.test.ts index f7d0f5f..1a3091f 100644 --- a/tests/transformer.parseResultAt.test.ts +++ b/tests/transformer.parseResultAt.test.ts @@ -31,19 +31,19 @@ for (let scenario of coords) { it(`matches start ${scenario.start}`, () => { const result = t.parseResultAt({ start: scenario.start }); - expect(result?.contentRange?.start).toEqual(scenario.start); + expect(result?.contentRange?.startByte).toEqual(scenario.start); }); it(`matches end ${scenario.end}`, () => { const result = t.parseResultAt({ end: scenario.end }); - expect(result?.contentRange?.end).toEqual(scenario.end); + expect(result?.contentRange?.endByte).toEqual(scenario.end); }); it(`matches whole thing ${scenario.start}`, () => { const result = t.parseResultAt(scenario); - expect(result?.contentRange?.end).toEqual(scenario.end); + expect(result?.contentRange?.endByte).toEqual(scenario.end); }); it(`matches line and column ${scenario.line} ${scenario.column}`, () => { @@ -52,6 +52,6 @@ for (let scenario of coords) { column: scenario.column, }); - expect(result?.contentRange?.end).toEqual(scenario.end); + expect(result?.contentRange?.endByte).toEqual(scenario.end); }); } diff --git a/tests/unprocess.test.ts b/tests/unprocess.test.ts index 384b6fd..e74f080 100644 --- a/tests/unprocess.test.ts +++ b/tests/unprocess.test.ts @@ -11,8 +11,14 @@ import { Preprocessor } from "content-tag"; let p = new Preprocessor(); +/** + * content-tag's process strips the whitespace around template contents, + * so a round-trip cannot restore newlines next to the template tags. + */ function normalizeCode(input: string) { return input + .replaceAll("\n") .split("\n") .map((x) => x.trim()) .filter(Boolean); @@ -79,8 +85,7 @@ it("implicitDefault.js", async () => { it("unicodeSingle", () => { let result = doUndo(unicodeSingle); - // @ts-expect-error - how do types for this work - expect(result).toMatchObject(unicodeSingle); + expect(result).toMatchCode(unicodeSingle); }); it("unicodeMulti", () => {