Skip to content

Commit

Permalink
feat: add support for <svelte:document> (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored Apr 7, 2023
1 parent 28619f1 commit 9856029
Show file tree
Hide file tree
Showing 31 changed files with 4,337 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/friendly-moles-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": minor
---

feat: add support for `<svelte:document>`
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"prettier-plugin-svelte": "^2.5.0",
"semver": "^7.3.5",
"string-replace-loader": "^3.0.3",
"svelte": "^3.46.1",
"svelte": "^3.57.0",
"typescript": "~5.0.0",
"vue-eslint-parser": "^9.0.0"
},
Expand Down
14 changes: 14 additions & 0 deletions src/parser/converts/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ export function* convertChildren(
yield convertConstTag(child, parent, ctx);
continue;
}
if (child.type === "Document") {
yield convertDocumentElement(child, parent, ctx);
continue;
}

throw new Error(`Unknown type:${(child as any).type}`);
}
Expand Down Expand Up @@ -328,6 +332,7 @@ function convertSpecialElement(
| SvAST.InlineComponent
| SvAST.Element
| SvAST.Window
| SvAST.Document
| SvAST.Body
| SvAST.Head
| SvAST.Options
Expand Down Expand Up @@ -590,6 +595,15 @@ function convertWindowElement(
return convertSpecialElement(node, parent, ctx);
}

/** Convert for document element. e.g. <svelte:document> */
function convertDocumentElement(
node: SvAST.Document,
parent: SvelteSpecialElement["parent"],
ctx: Context
): SvelteSpecialElement {
return convertSpecialElement(node, parent, ctx);
}

/** Convert for body element. e.g. <svelte:body> */
function convertBodyElement(
node: SvAST.Body,
Expand Down
7 changes: 7 additions & 0 deletions src/parser/svelte-ast-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export declare type TemplateNode =
| Element
| InlineComponent
| Window
| Document
| Body
| Head
| Title
Expand Down Expand Up @@ -134,6 +135,12 @@ export interface Window extends BaseNode {
children: TemplateNode[];
attributes: AttributeOrDirective[];
}
export interface Document extends BaseNode {
type: "Document";
name: "svelte:document";
children: TemplateNode[];
attributes: AttributeOrDirective[];
}
export interface Body extends BaseNode {
type: "Body";
name: "svelte:body";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<svelte:document on:event={handler}/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"ruleId": "no-undef",
"code": "handler",
"line": 1,
"column": 28
}
]
Loading

0 comments on commit 9856029

Please sign in to comment.