Skip to content

Commit 36f8d67

Browse files
committed
chore: Updated content-tag
1 parent 89aef80 commit 36f8d67

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
},
4949
"dependencies": {
5050
"@babel/core": "^7.27.4",
51-
"content-tag": "^3.1.2"
51+
"content-tag": "^4.0.0"
5252
},
5353
"devDependencies": {
5454
"@babel/eslint-parser": "^7.27.5",

src/parse/preprocess.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import {
77
} from '../utils/content-tag.js';
88

99
export interface Template {
10+
contentRange: Range;
1011
contents: string;
1112
range: Range;
12-
type: string;
13+
type: 'class-member' | 'expression';
1314
utf16Range: {
1415
end: number;
1516
start: number;
@@ -38,7 +39,7 @@ export function preprocessTemplateRange(
3839
prefix = '{/*';
3940
suffix = '*/}';
4041

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

4344
if (nextToken && (nextToken[0] === 'as' || nextToken[0] === 'satisfies')) {
4445
// Replace with parenthesized ObjectExpression
@@ -51,7 +52,7 @@ export function preprocessTemplateRange(
5152
// forward slash breaks the parsed templates.
5253
const contents = template.contents.replaceAll('/', PLACEHOLDER);
5354

54-
const templateLength = template.range.end - template.range.start;
55+
const templateLength = template.range.endByte - template.range.startByte;
5556
const spaces =
5657
templateLength - getBuffer(contents).length - prefix.length - suffix.length;
5758

@@ -69,8 +70,8 @@ export function codeToGlimmerAst(code: string, filename: string): Template[] {
6970
const { contentRange, contents, range, type } = contentTag;
7071

7172
const utf16Range = {
72-
end: sliceByteRange(code, 0, range.end).length,
73-
start: sliceByteRange(code, 0, range.start).length,
73+
end: sliceByteRange(code, 0, range.endByte).length,
74+
start: sliceByteRange(code, 0, range.startByte).length,
7475
};
7576

7677
return {

src/utils/content-tag.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ import {
33
type Parsed as ContentTag,
44
Preprocessor,
55
type PreprocessorOptions,
6+
type Range,
67
} from 'content-tag';
78

8-
type Range = {
9-
end: number;
10-
start: number;
11-
};
12-
139
const BufferMap = new Map<string, Buffer>();
1410

1511
export function getBuffer(string_: string): Buffer {
@@ -42,9 +38,9 @@ export function replaceContents(
4238
const { contents, range } = options;
4339

4440
return [
45-
sliceByteRange(file, 0, range.start),
41+
sliceByteRange(file, 0, range.startByte),
4642
contents,
47-
sliceByteRange(file, range.end),
43+
sliceByteRange(file, range.endByte),
4844
].join('');
4945
}
5046

0 commit comments

Comments
 (0)