Skip to content

Commit e96c12b

Browse files
committed
fix (wip)
1 parent 5751ee7 commit e96c12b

File tree

14 files changed

+16
-18
lines changed

14 files changed

+16
-18
lines changed

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: 2022,
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: 2022,
123123
sourceType: 'module',
124124
parser: { ts: tsParser, typescript: tsParser }
125125
},

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: 2022,
4545
sourceType: "module",
4646
loc: true,
4747
range: true,

src/parser/typescript/analyze/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,8 @@ function analyzeRuneVariables(
441441
// See https://github.com/sveltejs/svelte/blob/3fa3dd78a1cbaa88a1571977b76bf6f02ed4231d/packages/svelte/types/index.d.ts#L3416
442442
case "$props": {
443443
// Use type parameters to avoid `@typescript-eslint/no-unsafe-assignment` errors.
444-
appendDeclareFunctionVirtualScripts(globalName, ["(): any"]);
444+
// 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.
445+
appendDeclareFunctionVirtualScripts(globalName, ["<T>(): T"]);
445446
appendDeclareNamespaceVirtualScripts(globalName, [
446447
"export function id(): string;",
447448
]);

tests/fixtures/parser/ast/svelte5/async/_config.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,5 @@
55
"async": true
66
}
77
}
8-
},
9-
"parserOptions": {
10-
"ecmaVersion": 2022,
11-
"sourceType": "module"
128
}
139
}

tests/fixtures/parser/ast/svelte5/docs/snippets/10-typing-snippets-type-output.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
data: any[]; // data: any[]
66
children: Snippet; // children: Snippet<[]>, Snippet: Snippet<Parameters>
77
row: Snippet<[any]>; // row: Snippet<[any]>, Snippet: Snippet<Parameters>
8-
} = $props(); // $props(): any
8+
} = $props(); // $props(): { data: any[]; children: Snippet<[]>; row: Snippet<[any]>; }
99
</script>
1010

1111
<table>

tests/fixtures/parser/ast/svelte5/docs/snippets/11-typing-snippets-type-output.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
data: T[]; // data: unknown[], T: unknown
66
children: Snippet; // children: Snippet<[]>, Snippet: Snippet<Parameters>
77
row: Snippet<[T]>; // row: Snippet<[unknown]>, Snippet: Snippet<Parameters>, T: unknown
8-
} = $props(); // $props(): any
8+
} = $props(); // $props(): { data: unknown[]; children: Snippet<[]>; row: Snippet<[unknown]>; }
99
</script>
1010

1111
<table>

tests/fixtures/parser/ast/svelte5/generics01-snippets-type-output.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
data: A[]; // data: unknown[], A: unknown
77
children: Snippet; // children: Snippet<[]>, Snippet: Snippet<Parameters>
88
row: Snippet<[A]>; // row: Snippet<[unknown]>, Snippet: Snippet<Parameters>, A: unknown
9-
} = $props(); // $props(): any
9+
} = $props(); // $props(): { data: unknown[]; children: Snippet<[]>; row: Snippet<[unknown]>; }
1010
</script>
1111

1212
<table>

tests/fixtures/parser/ast/svelte5/ts-$props01-type-output.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
c: boolean; // c: boolean
66
d: number; // d: number
77
}
8-
let { a, b, c, ...everythingElse }: MyProps = $props(); // a: number, a: number, b: string, b: string, c: boolean, c: boolean, everythingElse: { d: number; }, MyProps: MyProps, $props(): any
8+
let { a, b, c, ...everythingElse }: MyProps = $props(); // a: number, a: number, b: string, b: string, c: boolean, c: boolean, everythingElse: { d: number; }, MyProps: MyProps, $props(): MyProps
99
</script>
1010

1111
{a} <!-- a: number -->
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
let { name }: { name: string } = $props(); // name: string, name: string, name: string, $props(): any
2+
let { name }: { name: string } = $props(); // name: string, name: string, name: string, $props(): { name: string; }
33
</script>
44

55
{name} <!-- name: string -->

0 commit comments

Comments
 (0)