Skip to content

Commit 685b797

Browse files
committed
fix
1 parent 505eef3 commit 685b797

10 files changed

+14888
-11
lines changed

Diff for: src/parser/converts/root.ts

+19-11
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,25 @@ function convertGenericsAttribute(script: SvelteScriptElement, ctx: Context) {
211211
return;
212212
}
213213
const value = genericsAttribute.value[0];
214+
215+
const genericValueCode = ctx.code.slice(value.range[0], value.range[1]);
216+
const scriptLet = `void function<${genericValueCode}>(){}`;
217+
let result: TSESParseForESLintResult;
218+
try {
219+
result = parseScriptWithoutAnalyzeScope(
220+
scriptLet,
221+
ctx.sourceCode.scripts.attrs,
222+
{
223+
...ctx.parserOptions,
224+
// Without typings
225+
project: null,
226+
},
227+
) as unknown as TSESParseForESLintResult;
228+
} catch {
229+
// ignore
230+
return;
231+
}
232+
214233
delete (genericsAttribute as any).boolean;
215234
delete (genericsAttribute as any).value;
216235

@@ -231,17 +250,6 @@ function convertGenericsAttribute(script: SvelteScriptElement, ctx: Context) {
231250
generics.type = "SvelteGenericsDirective";
232251
generics.params = [];
233252

234-
const genericValueCode = ctx.code.slice(value.range[0], value.range[1]);
235-
const scriptLet = `void function<${genericValueCode}>(){}`;
236-
const result = parseScriptWithoutAnalyzeScope(
237-
scriptLet,
238-
ctx.sourceCode.scripts.attrs,
239-
{
240-
...ctx.parserOptions,
241-
// Without typings
242-
project: null,
243-
},
244-
) as unknown as TSESParseForESLintResult;
245253
result.ast.tokens!.shift(); // void
246254
result.ast.tokens!.shift(); // function
247255
result.ast.tokens!.shift(); // <
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script lang="ts" generics="
2+
T extends {foo: number, bar: string} = {foo: 1, bar: '2'},
3+
U extends Record<string, T> = Record<string, T>,
4+
V extends [U,T] = [U,T],
5+
">
6+
export let array1: T[];
7+
export let array2: U[];
8+
export let array3: V[];
9+
</script>
10+
11+
{#each array1 as a}
12+
{a.foo} {a.bar}
13+
{/each}
14+
{#each array2 as a}
15+
{a.b.foo} {a.c.bar}
16+
{/each}
17+
{#each array3 as a}
18+
{a[0].b.foo} {a[1].bar}
19+
{/each}

0 commit comments

Comments
 (0)