Skip to content

feat: add support for <svelte:document> #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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