Skip to content
Closed
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
7 changes: 3 additions & 4 deletions src/parse/preprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
parse,
type Range,
replaceContents,
sliceByteRange,
} from '../utils/content-tag.js';

export interface Template {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 2 additions & 12 deletions src/utils/content-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Loading