Skip to content
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

feat: add support for <svelte:boundary> #609

Merged
merged 2 commits into from
Dec 1, 2024
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/gold-geese-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": minor
---

feat: add support for `<svelte:boundary>`
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
}
},
"dependencies": {
"eslint-scope": "^8.0.0",
"eslint-scope": "^8.2.0",
"eslint-visitor-keys": "^3.4.3",
"espree": "^9.6.1",
"postcss": "^8.4.39",
"postcss": "^8.4.49",
"postcss-scss": "^4.0.9"
},
"devDependencies": {
Expand Down Expand Up @@ -94,8 +94,8 @@
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-regexp": "^2.7.0",
"eslint-plugin-svelte": "^2.46.1",
"eslint-plugin-yml": "^1.15.0",
"globals": "^15.12.0",
"eslint-plugin-yml": "^1.16.0",
"globals": "^15.13.0",
"locate-character": "^3.0.0",
"magic-string": "^0.30.14",
"mocha": "^10.8.2",
Expand All @@ -106,7 +106,7 @@
"prettier-plugin-svelte": "^3.3.2",
"rimraf": "^6.0.1",
"semver": "^7.6.3",
"svelte": "^5.2.11",
"svelte": "^5.3.1",
"svelte2tsx": "^0.7.28",
"typescript": "~5.7.2",
"typescript-eslint": "^8.16.0",
Expand Down
4 changes: 3 additions & 1 deletion src/parser/analyze-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ export function analyzeSnippetsScope(
if (
parent.type === "SvelteElement" &&
(parent.kind === "component" ||
(parent.kind === "special" && parent.name.name === "svelte:component"))
(parent.kind === "special" &&
(parent.name.name === "svelte:component" ||
parent.name.name === "svelte:boundary")))
) {
const scope = getScopeFromNode(scopeManager, snippet.id);
const upperScope = scope.upper;
Expand Down
16 changes: 15 additions & 1 deletion src/parser/converts/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ export function* convertChildren(
yield convertDocumentElement(child, parent, ctx);
continue;
}
if (child.type === "SvelteBoundary") {
yield convertSvelteBoundaryElement(child, parent, ctx);
continue;
}

throw new Error(`Unknown type:${child.type}`);
}
Expand Down Expand Up @@ -415,7 +419,8 @@ function convertSpecialElement(
| Compiler.SvelteDocument
| Compiler.SvelteFragment
| Compiler.SvelteSelf
| Compiler.SvelteOptionsRaw,
| Compiler.SvelteOptionsRaw
| Compiler.SvelteBoundary,
parent: SvelteSpecialElement["parent"],
ctx: Context,
): SvelteSpecialElement {
Expand Down Expand Up @@ -898,6 +903,15 @@ function convertSlotTemplateElement(
return convertSpecialElement(node, parent, ctx);
}

/** Convert for <svelte:boundary> element. */
function convertSvelteBoundaryElement(
node: Compiler.SvelteBoundary,
parent: SvelteSpecialElement["parent"],
ctx: Context,
): SvelteSpecialElement {
return convertSpecialElement(node, parent, ctx);
}

/** Extract element tag and tokens */
export function extractElementTags<
E extends SvelteScriptElement | SvelteElement | SvelteStyleElement,
Expand Down
4 changes: 3 additions & 1 deletion src/parser/svelte-ast-types-for-v5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type SvelteHead = AST.SvelteHead;
export type SvelteOptionsRaw = AST.SvelteOptionsRaw;
export type SvelteSelf = AST.SvelteSelf;
export type SvelteWindow = AST.SvelteWindow;
export type SvelteBoundary = AST.SvelteBoundary;

export type IfBlock = AST.IfBlock;
export type EachBlock = AST.EachBlock;
Expand Down Expand Up @@ -59,7 +60,8 @@ export type ElementLike =
| SvelteHead
| SvelteOptionsRaw
| SvelteSelf
| SvelteWindow;
| SvelteWindow
| SvelteBoundary;
export type Block = EachBlock | IfBlock | AwaitBlock | KeyBlock | SnippetBlock;

export type Directive =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<svelte:boundary onerror={handler}>...</svelte:boundary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"ruleId": "no-undef",
"code": "handler",
"line": 1,
"column": 27
}
]
Loading
Loading