Skip to content

Commit 970f35d

Browse files
baseballyamaclaude
andcommitted
fix: add name_loc property for compatibility with Svelte 5.42+
Svelte 5.42+ added a required `name_loc` property to `BaseElement` and `BaseAttribute` interfaces. This change adds the property to manually constructed Attribute and SvelteOptionsRaw objects. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9b92dd8 commit 970f35d

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

src/parser/compat.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,25 @@ export function getOptionsFromRoot(
3434
): Compiler.SvelteOptionsRaw | null {
3535
const root = svelteAst as Compiler.Root;
3636
if (root.options) {
37+
// The name "svelte:options" starts after the opening "<"
38+
const nameStart = root.options.start + 1;
39+
const nameEnd = nameStart + "svelte:options".length;
3740
return {
3841
type: "SvelteOptions",
3942
name: "svelte:options",
43+
// name_loc is required in Svelte 5.42+
44+
name_loc: {
45+
start: { line: 0, column: nameStart },
46+
end: { line: 0, column: nameEnd },
47+
},
4048
attributes: root.options.attributes,
4149
fragment: {
4250
type: "Fragment",
4351
nodes: [],
4452
},
4553
start: root.options.start,
4654
end: root.options.end,
47-
};
55+
} as Compiler.SvelteOptionsRaw;
4856
}
4957
return null;
5058
}

src/parser/html.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,36 @@ function parseAttribute(state: State): Compiler.Attribute {
8383
return {
8484
type: "Attribute",
8585
name: key,
86+
// name_loc is required in Svelte 5.42+
87+
name_loc: null,
8688
value: true,
8789
start,
8890
end: keyEnd,
89-
};
91+
} as Compiler.Attribute;
9092
}
9193
state.skipSpaces();
9294
if (state.eof()) {
9395
return {
9496
type: "Attribute",
9597
name: key,
98+
// name_loc is required in Svelte 5.42+
99+
name_loc: null,
96100
value: true,
97101
start,
98102
end: keyEnd,
99-
};
103+
} as Compiler.Attribute;
100104
}
101105
// parse value
102106
const value = parseAttributeValue(state);
103107
return {
104108
type: "Attribute",
105109
name: key,
110+
// name_loc is required in Svelte 5.42+
111+
name_loc: null,
106112
value: [value],
107113
start,
108114
end: state.index,
109-
};
115+
} as Compiler.Attribute;
110116
}
111117

112118
/** Parse HTML attribute key */

tests/src/parser/__snapshots__/html.ts.snap

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Object {
1313
Object {
1414
"end": 17,
1515
"name": "lang",
16+
"name_loc": null,
1617
"start": 8,
1718
"type": "Attribute",
1819
"value": Array [
@@ -36,6 +37,7 @@ Object {
3637
Object {
3738
"end": 17,
3839
"name": "lang",
40+
"name_loc": null,
3941
"start": 8,
4042
"type": "Attribute",
4143
"value": Array [
@@ -59,6 +61,7 @@ Object {
5961
Object {
6062
"end": 15,
6163
"name": "lang",
64+
"name_loc": null,
6265
"start": 8,
6366
"type": "Attribute",
6467
"value": Array [
@@ -82,6 +85,7 @@ Object {
8285
Object {
8386
"end": 13,
8487
"name": "global",
88+
"name_loc": null,
8589
"start": 7,
8690
"type": "Attribute",
8791
"value": true,
@@ -97,6 +101,7 @@ Object {
97101
Object {
98102
"end": 13,
99103
"name": "global",
104+
"name_loc": null,
100105
"start": 7,
101106
"type": "Attribute",
102107
"value": true,
@@ -112,6 +117,7 @@ Object {
112117
Object {
113118
"end": 4,
114119
"name": "attr",
120+
"name_loc": null,
115121
"start": 0,
116122
"type": "Attribute",
117123
"value": true,
@@ -127,6 +133,7 @@ Object {
127133
Object {
128134
"end": 4,
129135
"name": "attr",
136+
"name_loc": null,
130137
"start": 0,
131138
"type": "Attribute",
132139
"value": true,
@@ -142,6 +149,7 @@ Object {
142149
Object {
143150
"end": 16,
144151
"name": "attr",
152+
"name_loc": null,
145153
"start": 0,
146154
"type": "Attribute",
147155
"value": Array [
@@ -165,6 +173,7 @@ Object {
165173
Object {
166174
"end": 12,
167175
"name": "attr",
176+
"name_loc": null,
168177
"start": 0,
169178
"type": "Attribute",
170179
"value": Array [
@@ -188,6 +197,7 @@ Object {
188197
Object {
189198
"end": 8,
190199
"name": "empty",
200+
"name_loc": null,
191201
"start": 0,
192202
"type": "Attribute",
193203
"value": Array [
@@ -211,6 +221,7 @@ Object {
211221
Object {
212222
"end": 8,
213223
"name": "empty",
224+
"name_loc": null,
214225
"start": 0,
215226
"type": "Attribute",
216227
"value": Array [
@@ -234,6 +245,7 @@ Object {
234245
Object {
235246
"end": 13,
236247
"name": "expr",
248+
"name_loc": null,
237249
"start": 0,
238250
"type": "Attribute",
239251
"value": Array [
@@ -263,6 +275,7 @@ Object {
263275
Object {
264276
"end": 13,
265277
"name": "expr",
278+
"name_loc": null,
266279
"start": 0,
267280
"type": "Attribute",
268281
"value": Array [
@@ -292,6 +305,7 @@ Object {
292305
Object {
293306
"end": 10,
294307
"name": "expr",
308+
"name_loc": null,
295309
"start": 0,
296310
"type": "Attribute",
297311
"value": Array [
@@ -321,6 +335,7 @@ Object {
321335
Object {
322336
"end": 10,
323337
"name": "expr",
338+
"name_loc": null,
324339
"start": 0,
325340
"type": "Attribute",
326341
"value": Array [
@@ -350,6 +365,7 @@ Object {
350365
Object {
351366
"end": 15,
352367
"name": "expr",
368+
"name_loc": null,
353369
"start": 0,
354370
"type": "Attribute",
355371
"value": Array [
@@ -387,6 +403,7 @@ Object {
387403
Object {
388404
"end": 19,
389405
"name": "expr",
406+
"name_loc": null,
390407
"start": 0,
391408
"type": "Attribute",
392409
"value": Array [
@@ -429,6 +446,7 @@ Object {
429446
Object {
430447
"end": 11,
431448
"name": "expr",
449+
"name_loc": null,
432450
"start": 0,
433451
"type": "Attribute",
434452
"value": Array [
@@ -458,6 +476,7 @@ Object {
458476
Object {
459477
"end": 9,
460478
"name": "quote",
479+
"name_loc": null,
461480
"start": 0,
462481
"type": "Attribute",
463482
"value": Array [
@@ -481,6 +500,7 @@ Object {
481500
Object {
482501
"end": 9,
483502
"name": "quote",
503+
"name_loc": null,
484504
"start": 0,
485505
"type": "Attribute",
486506
"value": Array [

0 commit comments

Comments
 (0)