Skip to content

Commit c3083a8

Browse files
committed
chore: update name, test and types
1 parent 949a332 commit c3083a8

File tree

5 files changed

+135
-6
lines changed

5 files changed

+135
-6
lines changed

packages/svelte/src/compiler/phases/1-parse/state/tag.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,14 @@ function open(parser) {
356356

357357
// snippets could have a generic signature, e.g. `#snippet foo<T>(...)`
358358
/** @type {string | undefined} */
359-
let generic;
359+
let type_params;
360360

361361
// if we match a generic opening
362362
if (parser.ts && parser.match('<')) {
363363
const start = parser.index;
364364
const end = match_bracket(parser, start, pointy_bois);
365365

366-
generic = parser.template.slice(start + 1, end - 1);
366+
type_params = parser.template.slice(start + 1, end - 1);
367367

368368
parser.index = end;
369369
}
@@ -407,7 +407,7 @@ function open(parser) {
407407
end: name_end,
408408
name
409409
},
410-
generic,
410+
typeParams: type_params,
411411
parameters: function_expression.params,
412412
body: create_fragment(),
413413
metadata: {

packages/svelte/src/compiler/types/template.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ export namespace AST {
468468
type: 'SnippetBlock';
469469
expression: Identifier;
470470
parameters: Pattern[];
471+
typeParams?: string;
471472
body: Fragment;
472473
/** @internal */
473474
metadata: {

packages/svelte/tests/parser-modern/samples/generic-snippets/input.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33

44
{#snippet generic<T extends string>(val: T)}
55
{val}
6+
{/snippet}
7+
8+
{#snippet complex_generic<T extends { bracket: "<" } | "<" | Set<"<>">>(val: T)}
9+
{val}
610
{/snippet}

packages/svelte/tests/parser-modern/samples/generic-snippets/output.json

Lines changed: 126 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"css": null,
33
"js": [],
44
"start": 30,
5-
"end": 92,
5+
"end": 192,
66
"type": "Root",
77
"fragment": {
88
"type": "Fragment",
@@ -24,7 +24,7 @@
2424
"end": 47,
2525
"name": "generic"
2626
},
27-
"generic": "T extends string",
27+
"typeParams": "T extends string",
2828
"parameters": [
2929
{
3030
"type": "Identifier",
@@ -129,6 +129,129 @@
129129
}
130130
]
131131
}
132+
},
133+
{
134+
"type": "Text",
135+
"start": 92,
136+
"end": 94,
137+
"raw": "\n\n",
138+
"data": "\n\n"
139+
},
140+
{
141+
"type": "SnippetBlock",
142+
"start": 94,
143+
"end": 192,
144+
"expression": {
145+
"type": "Identifier",
146+
"start": 104,
147+
"end": 119,
148+
"name": "complex_generic"
149+
},
150+
"typeParams": "T extends { bracket: \"<\" } | \"<\" | Set<\"<>\">",
151+
"parameters": [
152+
{
153+
"type": "Identifier",
154+
"start": 166,
155+
"end": 172,
156+
"loc": {
157+
"start": {
158+
"line": 8,
159+
"column": 72
160+
},
161+
"end": {
162+
"line": 8,
163+
"column": 78
164+
}
165+
},
166+
"name": "val",
167+
"typeAnnotation": {
168+
"type": "TSTypeAnnotation",
169+
"start": 169,
170+
"end": 172,
171+
"loc": {
172+
"start": {
173+
"line": 8,
174+
"column": 75
175+
},
176+
"end": {
177+
"line": 8,
178+
"column": 78
179+
}
180+
},
181+
"typeAnnotation": {
182+
"type": "TSTypeReference",
183+
"start": 171,
184+
"end": 172,
185+
"loc": {
186+
"start": {
187+
"line": 8,
188+
"column": 77
189+
},
190+
"end": {
191+
"line": 8,
192+
"column": 78
193+
}
194+
},
195+
"typeName": {
196+
"type": "Identifier",
197+
"start": 171,
198+
"end": 172,
199+
"loc": {
200+
"start": {
201+
"line": 8,
202+
"column": 77
203+
},
204+
"end": {
205+
"line": 8,
206+
"column": 78
207+
}
208+
},
209+
"name": "T"
210+
}
211+
}
212+
}
213+
}
214+
],
215+
"body": {
216+
"type": "Fragment",
217+
"nodes": [
218+
{
219+
"type": "Text",
220+
"start": 174,
221+
"end": 176,
222+
"raw": "\n\t",
223+
"data": "\n\t"
224+
},
225+
{
226+
"type": "ExpressionTag",
227+
"start": 176,
228+
"end": 181,
229+
"expression": {
230+
"type": "Identifier",
231+
"start": 177,
232+
"end": 180,
233+
"loc": {
234+
"start": {
235+
"line": 9,
236+
"column": 2
237+
},
238+
"end": {
239+
"line": 9,
240+
"column": 5
241+
}
242+
},
243+
"name": "val"
244+
}
245+
},
246+
{
247+
"type": "Text",
248+
"start": 181,
249+
"end": 182,
250+
"raw": "\n",
251+
"data": "\n"
252+
}
253+
]
254+
}
132255
}
133256
]
134257
},
@@ -173,4 +296,4 @@
173296
}
174297
]
175298
}
176-
}
299+
}

packages/svelte/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,7 @@ declare module 'svelte/compiler' {
13011301
type: 'SnippetBlock';
13021302
expression: Identifier;
13031303
parameters: Pattern[];
1304+
typeParams?: string;
13041305
body: Fragment;
13051306
}
13061307

0 commit comments

Comments
 (0)