diff --git a/src/parser/compat.ts b/src/parser/compat.ts index d3a1ce07..4d512b42 100644 --- a/src/parser/compat.ts +++ b/src/parser/compat.ts @@ -34,9 +34,17 @@ export function getOptionsFromRoot( ): Compiler.SvelteOptionsRaw | null { const root = svelteAst as Compiler.Root; if (root.options) { + // The name "svelte:options" starts after the opening "<" + const nameStart = root.options.start + 1; + const nameEnd = nameStart + "svelte:options".length; return { type: "SvelteOptions", name: "svelte:options", + // name_loc is required in Svelte 5.42+ + name_loc: { + start: { line: 0, column: nameStart }, + end: { line: 0, column: nameEnd }, + }, attributes: root.options.attributes, fragment: { type: "Fragment", @@ -44,7 +52,7 @@ export function getOptionsFromRoot( }, start: root.options.start, end: root.options.end, - }; + } as Compiler.SvelteOptionsRaw; } return null; } diff --git a/src/parser/html.ts b/src/parser/html.ts index 6c713bc8..019f5b79 100644 --- a/src/parser/html.ts +++ b/src/parser/html.ts @@ -83,30 +83,36 @@ function parseAttribute(state: State): Compiler.Attribute { return { type: "Attribute", name: key, + // name_loc is required in Svelte 5.42+ + name_loc: null, value: true, start, end: keyEnd, - }; + } as Compiler.Attribute; } state.skipSpaces(); if (state.eof()) { return { type: "Attribute", name: key, + // name_loc is required in Svelte 5.42+ + name_loc: null, value: true, start, end: keyEnd, - }; + } as Compiler.Attribute; } // parse value const value = parseAttributeValue(state); return { type: "Attribute", name: key, + // name_loc is required in Svelte 5.42+ + name_loc: null, value: [value], start, end: state.index, - }; + } as Compiler.Attribute; } /** Parse HTML attribute key */ diff --git a/tests/src/parser/__snapshots__/html.ts.snap b/tests/src/parser/__snapshots__/html.ts.snap index bffe7bf1..54740751 100644 --- a/tests/src/parser/__snapshots__/html.ts.snap +++ b/tests/src/parser/__snapshots__/html.ts.snap @@ -13,6 +13,7 @@ Object { Object { "end": 17, "name": "lang", + "name_loc": null, "start": 8, "type": "Attribute", "value": Array [ @@ -36,6 +37,7 @@ Object { Object { "end": 17, "name": "lang", + "name_loc": null, "start": 8, "type": "Attribute", "value": Array [ @@ -59,6 +61,7 @@ Object { Object { "end": 15, "name": "lang", + "name_loc": null, "start": 8, "type": "Attribute", "value": Array [ @@ -82,6 +85,7 @@ Object { Object { "end": 13, "name": "global", + "name_loc": null, "start": 7, "type": "Attribute", "value": true, @@ -97,6 +101,7 @@ Object { Object { "end": 13, "name": "global", + "name_loc": null, "start": 7, "type": "Attribute", "value": true, @@ -112,6 +117,7 @@ Object { Object { "end": 4, "name": "attr", + "name_loc": null, "start": 0, "type": "Attribute", "value": true, @@ -127,6 +133,7 @@ Object { Object { "end": 4, "name": "attr", + "name_loc": null, "start": 0, "type": "Attribute", "value": true, @@ -142,6 +149,7 @@ Object { Object { "end": 16, "name": "attr", + "name_loc": null, "start": 0, "type": "Attribute", "value": Array [ @@ -165,6 +173,7 @@ Object { Object { "end": 12, "name": "attr", + "name_loc": null, "start": 0, "type": "Attribute", "value": Array [ @@ -188,6 +197,7 @@ Object { Object { "end": 8, "name": "empty", + "name_loc": null, "start": 0, "type": "Attribute", "value": Array [ @@ -211,6 +221,7 @@ Object { Object { "end": 8, "name": "empty", + "name_loc": null, "start": 0, "type": "Attribute", "value": Array [ @@ -234,6 +245,7 @@ Object { Object { "end": 13, "name": "expr", + "name_loc": null, "start": 0, "type": "Attribute", "value": Array [ @@ -263,6 +275,7 @@ Object { Object { "end": 13, "name": "expr", + "name_loc": null, "start": 0, "type": "Attribute", "value": Array [ @@ -292,6 +305,7 @@ Object { Object { "end": 10, "name": "expr", + "name_loc": null, "start": 0, "type": "Attribute", "value": Array [ @@ -321,6 +335,7 @@ Object { Object { "end": 10, "name": "expr", + "name_loc": null, "start": 0, "type": "Attribute", "value": Array [ @@ -350,6 +365,7 @@ Object { Object { "end": 15, "name": "expr", + "name_loc": null, "start": 0, "type": "Attribute", "value": Array [ @@ -387,6 +403,7 @@ Object { Object { "end": 19, "name": "expr", + "name_loc": null, "start": 0, "type": "Attribute", "value": Array [ @@ -429,6 +446,7 @@ Object { Object { "end": 11, "name": "expr", + "name_loc": null, "start": 0, "type": "Attribute", "value": Array [ @@ -458,6 +476,7 @@ Object { Object { "end": 9, "name": "quote", + "name_loc": null, "start": 0, "type": "Attribute", "value": Array [ @@ -481,6 +500,7 @@ Object { Object { "end": 9, "name": "quote", + "name_loc": null, "start": 0, "type": "Attribute", "value": Array [