Skip to content

Commit 1710145

Browse files
authored
feat: async Svelte (#725)
1 parent 1d72818 commit 1710145

38 files changed

+22996
-42
lines changed

.changeset/huge-islands-crash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-eslint-parser": minor
3+
---
4+
5+
feat: support asynchronous svelte

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# svelte-eslint-parser
1414

15-
## [Svelte](https://svelte.dev/) parser for [ESLint](https://eslint.org/).
15+
## [Svelte](https://svelte.dev/) parser for [ESLint](https://eslint.org/)
1616

1717
[Live DEMO](https://sveltejs.github.io/svelte-eslint-parser/playground)
1818
[Discord](https://svelte.dev/chat)
@@ -100,7 +100,7 @@ export default [
100100
parser: svelteParser,
101101
parserOptions: {
102102
sourceType: "module",
103-
ecmaVersion: 2021,
103+
ecmaVersion: 2024,
104104
ecmaFeatures: {
105105
globalReturn: false,
106106
impliedStrict: false,

explorer-v2/src/lib/ESLintPlayground.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
languageOptions: {
120120
parser: svelteEslintParser,
121121
parserOptions: {
122-
ecmaVersion: 2020,
122+
ecmaVersion: 2024,
123123
sourceType: 'module',
124124
parser: { ts: tsParser, typescript: tsParser }
125125
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"prettier-plugin-svelte": "^3.3.3",
106106
"rimraf": "^6.0.1",
107107
"semver": "^7.7.1",
108-
"svelte": "^5.30.1",
108+
"svelte": "^5.36.2",
109109
"svelte2tsx": "^0.7.35",
110110
"tsx": "^4.19.3",
111111
"typescript": "~5.8.2",

src/parser/compat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type * as SvAST from "./svelte-ast-types.js";
44
import type * as Compiler from "./svelte-ast-types-for-v5.js";
55

66
export type Child =
7+
| Compiler.AttachTag
78
| Compiler.Text
89
| Compiler.Tag
910
| Compiler.ElementLike

src/parser/parser-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export type NormalizedParserOptions = {
4141
/** Normalize parserOptions */
4242
export function normalizeParserOptions(options: any): NormalizedParserOptions {
4343
const parserOptions = {
44-
ecmaVersion: 2020,
44+
ecmaVersion: 2024,
4545
sourceType: "module",
4646
loc: true,
4747
range: true,

src/parser/typescript/analyze/index.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ function analyzeRuneVariables(
399399
continue;
400400
}
401401
switch (globalName) {
402-
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L2679
402+
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3093
403403
case "$state": {
404404
appendDeclareFunctionVirtualScripts(globalName, [
405405
"<T>(initial: T): T",
@@ -415,7 +415,7 @@ function analyzeRuneVariables(
415415

416416
break;
417417
}
418-
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L2833
418+
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3247
419419
case "$derived": {
420420
appendDeclareFunctionVirtualScripts(globalName, [
421421
"<T>(expression: T): T",
@@ -425,35 +425,36 @@ function analyzeRuneVariables(
425425
]);
426426
break;
427427
}
428-
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L2893
428+
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3307
429429
case "$effect": {
430430
appendDeclareFunctionVirtualScripts(globalName, [
431431
"(fn: () => void | (() => void)): void",
432432
]);
433433
appendDeclareNamespaceVirtualScripts(globalName, [
434434
"export function pre(fn: () => void | (() => void)): void;",
435+
"export function pending(): number;",
435436
"export function tracking(): boolean;",
436437
"export function root(fn: () => void | (() => void)): () => void;",
437438
]);
438439
break;
439440
}
440-
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L2997
441+
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3416
441442
case "$props": {
442-
// Use type parameters to avoid `@typescript-eslint/no-unsafe-assignment` errors.
443+
// NOTE: In the Svelte repository's `index.d.ts`, the return type is any, but that triggers `@typescript-eslint/no-unsafe-assignment`. To avoid this, use generics here.
443444
appendDeclareFunctionVirtualScripts(globalName, ["<T>(): T"]);
444445
appendDeclareNamespaceVirtualScripts(globalName, [
445446
"export function id(): string;",
446447
]);
447448
break;
448449
}
449-
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L3038
450+
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3459
450451
case "$bindable": {
451452
appendDeclareFunctionVirtualScripts(globalName, [
452453
"<T>(fallback?: T): T",
453454
]);
454455
break;
455456
}
456-
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L3081
457+
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3502
457458
case "$inspect": {
458459
appendDeclareFunctionVirtualScripts(globalName, [
459460
`<T extends any[]>(...values: T): { with: (fn: (type: 'init' | 'update', ...values: T) => void) => void }`,
@@ -463,7 +464,7 @@ function analyzeRuneVariables(
463464
]);
464465
break;
465466
}
466-
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L3144
467+
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3565
467468
case "$host": {
468469
appendDeclareFunctionVirtualScripts(globalName, [
469470
`<El extends HTMLElement = HTMLElement>(): El`,

tests/fixtures/parser/ast/issue338-eslint-plugin-svelte-output.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@
940940
}
941941
},
942942
{
943-
"type": "Keyword",
943+
"type": "Null",
944944
"value": "null",
945945
"range": [
946946
46,
@@ -976,7 +976,7 @@
976976
}
977977
},
978978
{
979-
"type": "Keyword",
979+
"type": "Null",
980980
"value": "null",
981981
"range": [
982982
53,
@@ -1516,7 +1516,7 @@
15161516
}
15171517
},
15181518
{
1519-
"type": "Keyword",
1519+
"type": "Null",
15201520
"value": "null",
15211521
"range": [
15221522
136,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"svelteConfig": {
3+
"compilerOptions": {
4+
"experimental": {
5+
"async": true
6+
}
7+
}
8+
}
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
import MyApp from './MyApp.svelte';
3+
</script>
4+
5+
<svelte:boundary>
6+
<MyApp />
7+
8+
{#snippet pending()}
9+
<p>loading...</p>
10+
{/snippet}
11+
</svelte:boundary>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy