Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# svelte-eslint-parser

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

[Live DEMO](https://sveltejs.github.io/svelte-eslint-parser/playground) •
[Discord](https://svelte.dev/chat)
Expand Down Expand Up @@ -100,7 +100,7 @@ export default [
parser: svelteParser,
parserOptions: {
sourceType: "module",
ecmaVersion: 2021,
ecmaVersion: 2022,
ecmaFeatures: {
globalReturn: false,
impliedStrict: false,
Expand Down
2 changes: 1 addition & 1 deletion explorer-v2/src/lib/ESLintPlayground.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
languageOptions: {
parser: svelteEslintParser,
parserOptions: {
ecmaVersion: 2020,
ecmaVersion: 2022,
sourceType: 'module',
parser: { ts: tsParser, typescript: tsParser }
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"prettier-plugin-svelte": "^3.3.3",
"rimraf": "^6.0.1",
"semver": "^7.7.1",
"svelte": "^5.30.1",
"svelte": "^5.36.2",
"svelte2tsx": "^0.7.35",
"tsx": "^4.19.3",
"typescript": "~5.8.2",
Expand Down
1 change: 1 addition & 0 deletions src/parser/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type * as SvAST from "./svelte-ast-types.js";
import type * as Compiler from "./svelte-ast-types-for-v5.js";

export type Child =
| Compiler.AttachTag
| Compiler.Text
| Compiler.Tag
| Compiler.ElementLike
Expand Down
2 changes: 1 addition & 1 deletion src/parser/parser-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type NormalizedParserOptions = {
/** Normalize parserOptions */
export function normalizeParserOptions(options: any): NormalizedParserOptions {
const parserOptions = {
ecmaVersion: 2020,
ecmaVersion: 2022,
sourceType: "module",
loc: true,
range: true,
Expand Down
16 changes: 9 additions & 7 deletions src/parser/typescript/analyze/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ function analyzeRuneVariables(
continue;
}
switch (globalName) {
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L2679
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3093
case "$state": {
appendDeclareFunctionVirtualScripts(globalName, [
"<T>(initial: T): T",
Expand All @@ -415,7 +415,7 @@ function analyzeRuneVariables(

break;
}
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L2833
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3247
case "$derived": {
appendDeclareFunctionVirtualScripts(globalName, [
"<T>(expression: T): T",
Expand All @@ -425,35 +425,37 @@ function analyzeRuneVariables(
]);
break;
}
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L2893
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3307
case "$effect": {
appendDeclareFunctionVirtualScripts(globalName, [
"(fn: () => void | (() => void)): void",
]);
appendDeclareNamespaceVirtualScripts(globalName, [
"export function pre(fn: () => void | (() => void)): void;",
"export function pending(): number;",
"export function tracking(): boolean;",
"export function root(fn: () => void | (() => void)): () => void;",
]);
break;
}
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L2997
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3416
case "$props": {
// Use type parameters to avoid `@typescript-eslint/no-unsafe-assignment` errors.
Copy link
Member

@ota-meshi ota-meshi Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the new comment explains it better, so I think this old comment is no longer necessary.

Suggested change
// Use type parameters to avoid `@typescript-eslint/no-unsafe-assignment` errors.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed: 67b5adf

// 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.
appendDeclareFunctionVirtualScripts(globalName, ["<T>(): T"]);
appendDeclareNamespaceVirtualScripts(globalName, [
"export function id(): string;",
]);
break;
}
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L3038
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3459
case "$bindable": {
appendDeclareFunctionVirtualScripts(globalName, [
"<T>(fallback?: T): T",
]);
break;
}
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L3081
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3502
case "$inspect": {
appendDeclareFunctionVirtualScripts(globalName, [
`<T extends any[]>(...values: T): { with: (fn: (type: 'init' | 'update', ...values: T) => void) => void }`,
Expand All @@ -463,7 +465,7 @@ function analyzeRuneVariables(
]);
break;
}
// See https://github.com/sveltejs/svelte/blob/3c4a8d425b8192dc11ea2af256d531c51c37ba5d/packages/svelte/types/index.d.ts#L3144
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3565
case "$host": {
appendDeclareFunctionVirtualScripts(globalName, [
`<El extends HTMLElement = HTMLElement>(): El`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@
}
},
{
"type": "Keyword",
"type": "Null",
"value": "null",
"range": [
46,
Expand Down Expand Up @@ -976,7 +976,7 @@
}
},
{
"type": "Keyword",
"type": "Null",
"value": "null",
"range": [
53,
Expand Down Expand Up @@ -1516,7 +1516,7 @@
}
},
{
"type": "Keyword",
"type": "Null",
"value": "null",
"range": [
136,
Expand Down
9 changes: 9 additions & 0 deletions tests/fixtures/parser/ast/svelte5/async/_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"svelteConfig": {
"compilerOptions": {
"experimental": {
"async": true
}
}
}
}
11 changes: 11 additions & 0 deletions tests/fixtures/parser/ast/svelte5/async/boundaries-input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script>
import MyApp from './MyApp.svelte';
</script>

<svelte:boundary>
<MyApp />

{#snippet pending()}
<p>loading...</p>
{/snippet}
</svelte:boundary>
Loading
Loading