Skip to content

Commit e4451fa

Browse files
committed
Use content-tag @ v4 features to avoid buffer math
1 parent a7f3d34 commit e4451fa

2 files changed

Lines changed: 5 additions & 16 deletions

File tree

src/parse/preprocess.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
parse,
44
type Range,
55
replaceContents,
6-
sliceByteRange,
76
} from '../utils/content-tag.js';
87

98
export interface Template {
@@ -39,7 +38,7 @@ export function preprocessTemplateRange(
3938
prefix = '{/*';
4039
suffix = '*/}';
4140

42-
const nextToken = sliceByteRange(code, template.range.endByte).match(/\S+/);
41+
const nextToken = code.slice(template.range.endChar).match(/\S+/);
4342

4443
if (nextToken && (nextToken[0] === 'as' || nextToken[0] === 'satisfies')) {
4544
// Replace with parenthesized ObjectExpression
@@ -70,8 +69,8 @@ export function codeToGlimmerAst(code: string, filename: string): Template[] {
7069
const { contentRange, contents, range, type } = contentTag;
7170

7271
const utf16Range = {
73-
end: sliceByteRange(code, 0, range.endByte).length,
74-
start: sliceByteRange(code, 0, range.startByte).length,
72+
end: code.slice(0, range.endChar).length,
73+
start: code.slice(0, range.startChar).length,
7574
};
7675

7776
return {

src/utils/content-tag.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,10 @@ export function replaceContents(
3838
const { contents, range } = options;
3939

4040
return [
41-
sliceByteRange(file, 0, range.startByte),
41+
file.slice(0, range.startChar),
4242
contents,
43-
sliceByteRange(file, range.endByte),
43+
file.slice(range.endChar),
4444
].join('');
4545
}
4646

47-
export function sliceByteRange(
48-
string_: string,
49-
indexStart: number,
50-
indexEnd?: number,
51-
): string {
52-
const buffer = getBuffer(string_);
53-
54-
return buffer.slice(indexStart, indexEnd).toString();
55-
}
56-
5747
export type { ContentTag, Range };

0 commit comments

Comments
 (0)