diff --git a/src/parse/preprocess.ts b/src/parse/preprocess.ts index 6241f6e..5ce5bb4 100644 --- a/src/parse/preprocess.ts +++ b/src/parse/preprocess.ts @@ -3,7 +3,6 @@ import { parse, type Range, replaceContents, - sliceByteRange, } from '../utils/content-tag.js'; export interface Template { @@ -39,7 +38,7 @@ export function preprocessTemplateRange( prefix = '{/*'; suffix = '*/}'; - const nextToken = sliceByteRange(code, template.range.endByte).match(/\S+/); + const nextToken = code.slice(template.range.endChar).match(/\S+/); if (nextToken && (nextToken[0] === 'as' || nextToken[0] === 'satisfies')) { // Replace with parenthesized ObjectExpression @@ -70,8 +69,8 @@ export function codeToGlimmerAst(code: string, filename: string): Template[] { const { contentRange, contents, range, type } = contentTag; const utf16Range = { - end: sliceByteRange(code, 0, range.endByte).length, - start: sliceByteRange(code, 0, range.startByte).length, + end: code.slice(0, range.endChar).length, + start: code.slice(0, range.startChar).length, }; return { diff --git a/src/utils/content-tag.ts b/src/utils/content-tag.ts index 6623444..d009928 100644 --- a/src/utils/content-tag.ts +++ b/src/utils/content-tag.ts @@ -38,20 +38,10 @@ export function replaceContents( const { contents, range } = options; return [ - sliceByteRange(file, 0, range.startByte), + file.slice(0, range.startChar), contents, - sliceByteRange(file, range.endByte), + file.slice(range.endChar), ].join(''); } -export function sliceByteRange( - string_: string, - indexStart: number, - indexEnd?: number, -): string { - const buffer = getBuffer(string_); - - return buffer.slice(indexStart, indexEnd).toString(); -} - export type { ContentTag, Range };