Skip to content

Commit 9856029

Browse files
authored
feat: add support for <svelte:document> (#312)
1 parent 28619f1 commit 9856029

31 files changed

+4337
-1
lines changed

.changeset/friendly-moles-appear.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-eslint-parser": minor
3+
---
4+
5+
feat: add support for `<svelte:document>`

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"prettier-plugin-svelte": "^2.5.0",
9898
"semver": "^7.3.5",
9999
"string-replace-loader": "^3.0.3",
100-
"svelte": "^3.46.1",
100+
"svelte": "^3.57.0",
101101
"typescript": "~5.0.0",
102102
"vue-eslint-parser": "^9.0.0"
103103
},

src/parser/converts/element.ts

+14
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ export function* convertChildren(
166166
yield convertConstTag(child, parent, ctx);
167167
continue;
168168
}
169+
if (child.type === "Document") {
170+
yield convertDocumentElement(child, parent, ctx);
171+
continue;
172+
}
169173

170174
throw new Error(`Unknown type:${(child as any).type}`);
171175
}
@@ -328,6 +332,7 @@ function convertSpecialElement(
328332
| SvAST.InlineComponent
329333
| SvAST.Element
330334
| SvAST.Window
335+
| SvAST.Document
331336
| SvAST.Body
332337
| SvAST.Head
333338
| SvAST.Options
@@ -590,6 +595,15 @@ function convertWindowElement(
590595
return convertSpecialElement(node, parent, ctx);
591596
}
592597

598+
/** Convert for document element. e.g. <svelte:document> */
599+
function convertDocumentElement(
600+
node: SvAST.Document,
601+
parent: SvelteSpecialElement["parent"],
602+
ctx: Context
603+
): SvelteSpecialElement {
604+
return convertSpecialElement(node, parent, ctx);
605+
}
606+
593607
/** Convert for body element. e.g. <svelte:body> */
594608
function convertBodyElement(
595609
node: SvAST.Body,

src/parser/svelte-ast-types.ts

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export declare type TemplateNode =
2020
| Element
2121
| InlineComponent
2222
| Window
23+
| Document
2324
| Body
2425
| Head
2526
| Title
@@ -134,6 +135,12 @@ export interface Window extends BaseNode {
134135
children: TemplateNode[];
135136
attributes: AttributeOrDirective[];
136137
}
138+
export interface Document extends BaseNode {
139+
type: "Document";
140+
name: "svelte:document";
141+
children: TemplateNode[];
142+
attributes: AttributeOrDirective[];
143+
}
137144
export interface Body extends BaseNode {
138145
type: "Body";
139146
name: "svelte:body";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<svelte:document on:event={handler}/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"ruleId": "no-undef",
4+
"code": "handler",
5+
"line": 1,
6+
"column": 28
7+
}
8+
]

0 commit comments

Comments
 (0)