Skip to content

Commit 47b61de

Browse files
authoredDec 1, 2024··
feat: add support for <svelte:boundary> (#609)
1 parent d768a5c commit 47b61de

26 files changed

+11976
-8
lines changed
 

‎.changeset/gold-geese-refuse.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:boundary>`

‎package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@
5555
}
5656
},
5757
"dependencies": {
58-
"eslint-scope": "^8.0.0",
58+
"eslint-scope": "^8.2.0",
5959
"eslint-visitor-keys": "^3.4.3",
6060
"espree": "^9.6.1",
61-
"postcss": "^8.4.39",
61+
"postcss": "^8.4.49",
6262
"postcss-scss": "^4.0.9"
6363
},
6464
"devDependencies": {
@@ -94,8 +94,8 @@
9494
"eslint-plugin-prettier": "^5.2.1",
9595
"eslint-plugin-regexp": "^2.7.0",
9696
"eslint-plugin-svelte": "^2.46.1",
97-
"eslint-plugin-yml": "^1.15.0",
98-
"globals": "^15.12.0",
97+
"eslint-plugin-yml": "^1.16.0",
98+
"globals": "^15.13.0",
9999
"locate-character": "^3.0.0",
100100
"magic-string": "^0.30.14",
101101
"mocha": "^10.8.2",
@@ -106,7 +106,7 @@
106106
"prettier-plugin-svelte": "^3.3.2",
107107
"rimraf": "^6.0.1",
108108
"semver": "^7.6.3",
109-
"svelte": "^5.2.11",
109+
"svelte": "^5.3.1",
110110
"svelte2tsx": "^0.7.28",
111111
"typescript": "~5.7.2",
112112
"typescript-eslint": "^8.16.0",

‎src/parser/analyze-scope.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ export function analyzeSnippetsScope(
294294
if (
295295
parent.type === "SvelteElement" &&
296296
(parent.kind === "component" ||
297-
(parent.kind === "special" && parent.name.name === "svelte:component"))
297+
(parent.kind === "special" &&
298+
(parent.name.name === "svelte:component" ||
299+
parent.name.name === "svelte:boundary")))
298300
) {
299301
const scope = getScopeFromNode(scopeManager, snippet.id);
300302
const upperScope = scope.upper;

‎src/parser/converts/element.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ export function* convertChildren(
210210
yield convertDocumentElement(child, parent, ctx);
211211
continue;
212212
}
213+
if (child.type === "SvelteBoundary") {
214+
yield convertSvelteBoundaryElement(child, parent, ctx);
215+
continue;
216+
}
213217

214218
throw new Error(`Unknown type:${child.type}`);
215219
}
@@ -415,7 +419,8 @@ function convertSpecialElement(
415419
| Compiler.SvelteDocument
416420
| Compiler.SvelteFragment
417421
| Compiler.SvelteSelf
418-
| Compiler.SvelteOptionsRaw,
422+
| Compiler.SvelteOptionsRaw
423+
| Compiler.SvelteBoundary,
419424
parent: SvelteSpecialElement["parent"],
420425
ctx: Context,
421426
): SvelteSpecialElement {
@@ -898,6 +903,15 @@ function convertSlotTemplateElement(
898903
return convertSpecialElement(node, parent, ctx);
899904
}
900905

906+
/** Convert for <svelte:boundary> element. */
907+
function convertSvelteBoundaryElement(
908+
node: Compiler.SvelteBoundary,
909+
parent: SvelteSpecialElement["parent"],
910+
ctx: Context,
911+
): SvelteSpecialElement {
912+
return convertSpecialElement(node, parent, ctx);
913+
}
914+
901915
/** Extract element tag and tokens */
902916
export function extractElementTags<
903917
E extends SvelteScriptElement | SvelteElement | SvelteStyleElement,

‎src/parser/svelte-ast-types-for-v5.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type SvelteHead = AST.SvelteHead;
2626
export type SvelteOptionsRaw = AST.SvelteOptionsRaw;
2727
export type SvelteSelf = AST.SvelteSelf;
2828
export type SvelteWindow = AST.SvelteWindow;
29+
export type SvelteBoundary = AST.SvelteBoundary;
2930

3031
export type IfBlock = AST.IfBlock;
3132
export type EachBlock = AST.EachBlock;
@@ -59,7 +60,8 @@ export type ElementLike =
5960
| SvelteHead
6061
| SvelteOptionsRaw
6162
| SvelteSelf
62-
| SvelteWindow;
63+
| SvelteWindow
64+
| SvelteBoundary;
6365
export type Block = EachBlock | IfBlock | AwaitBlock | KeyBlock | SnippetBlock;
6466

6567
export type Directive =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<svelte:boundary onerror={handler}>...</svelte:boundary>
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": 27
7+
}
8+
]

0 commit comments

Comments
 (0)
Please sign in to comment.