Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"test": "vitest"
},
"dependencies": {
"content-tag": "^3.1.2",
"content-tag": "^4.2.0",
"jscodeshift": "^17.2.0"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/coordinates-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/internal-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down
11 changes: 7 additions & 4 deletions src/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,18 @@ 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();
}

/**
* @param {ParseResult} parseResult
*/
originalContentOf(parseResult) {
return this.#buffer
.slice(parseResult.contentRange.start, parseResult.contentRange.end)
.slice(
parseResult.contentRange.startByte,
parseResult.contentRange.endByte,
)
.toString();
}

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/transformer.parseResultAt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`, () => {
Expand All @@ -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);
});
}
9 changes: 7 additions & 2 deletions tests/unprocess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("<template>", "\n<template>\n")
.replaceAll("</template>", "\n</template>\n")
.split("\n")
.map((x) => x.trim())
.filter(Boolean);
Expand Down Expand Up @@ -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", () => {
Expand Down
Loading