File tree Expand file tree Collapse file tree 4 files changed +261
-1
lines changed
tests/parser-legacy/samples/generic-snippets Expand file tree Collapse file tree 4 files changed +261
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' svelte ' : patch
3+ ---
4+
5+ fix: add ` typeParams ` to ` SnippetBlock ` for legacy parser
Original file line number Diff line number Diff line change @@ -378,7 +378,8 @@ export function convert(source, ast) {
378378 end : node . end ,
379379 expression : node . expression ,
380380 parameters : node . parameters ,
381- children : node . body . nodes . map ( ( child ) => visit ( child ) )
381+ children : node . body . nodes . map ( ( child ) => visit ( child ) ) ,
382+ typeParams : node . typeParams
382383 } ;
383384 } ,
384385 // @ts -expect-error
Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ </script >
3+
4+ {#snippet generic <T extends string >(val : T )}
5+ {val }
6+ {/ snippet }
7+
8+ {#snippet complex_generic < T extends { bracket : " <" } | " <" | Set < " <>" >> (val : T )}
9+ {val }
10+ {/ snippet }
Original file line number Diff line number Diff line change 1+ {
2+ "html" : {
3+ "type" : " Fragment" ,
4+ "start" : 30 ,
5+ "end" : 192 ,
6+ "children" : [
7+ {
8+ "type" : " Text" ,
9+ "start" : 28 ,
10+ "end" : 30 ,
11+ "raw" : " \n\n " ,
12+ "data" : " \n\n "
13+ },
14+ {
15+ "type" : " SnippetBlock" ,
16+ "start" : 30 ,
17+ "end" : 92 ,
18+ "expression" : {
19+ "type" : " Identifier" ,
20+ "start" : 40 ,
21+ "end" : 47 ,
22+ "name" : " generic"
23+ },
24+ "parameters" : [
25+ {
26+ "type" : " Identifier" ,
27+ "start" : 66 ,
28+ "end" : 72 ,
29+ "loc" : {
30+ "start" : {
31+ "line" : 4 ,
32+ "column" : 36
33+ },
34+ "end" : {
35+ "line" : 4 ,
36+ "column" : 42
37+ }
38+ },
39+ "name" : " val" ,
40+ "typeAnnotation" : {
41+ "type" : " TSTypeAnnotation" ,
42+ "start" : 69 ,
43+ "end" : 72 ,
44+ "loc" : {
45+ "start" : {
46+ "line" : 4 ,
47+ "column" : 39
48+ },
49+ "end" : {
50+ "line" : 4 ,
51+ "column" : 42
52+ }
53+ },
54+ "typeAnnotation" : {
55+ "type" : " TSTypeReference" ,
56+ "start" : 71 ,
57+ "end" : 72 ,
58+ "loc" : {
59+ "start" : {
60+ "line" : 4 ,
61+ "column" : 41
62+ },
63+ "end" : {
64+ "line" : 4 ,
65+ "column" : 42
66+ }
67+ },
68+ "typeName" : {
69+ "type" : " Identifier" ,
70+ "start" : 71 ,
71+ "end" : 72 ,
72+ "loc" : {
73+ "start" : {
74+ "line" : 4 ,
75+ "column" : 41
76+ },
77+ "end" : {
78+ "line" : 4 ,
79+ "column" : 42
80+ }
81+ },
82+ "name" : " T"
83+ }
84+ }
85+ }
86+ }
87+ ],
88+ "children" : [
89+ {
90+ "type" : " MustacheTag" ,
91+ "start" : 76 ,
92+ "end" : 81 ,
93+ "expression" : {
94+ "type" : " Identifier" ,
95+ "start" : 77 ,
96+ "end" : 80 ,
97+ "loc" : {
98+ "start" : {
99+ "line" : 5 ,
100+ "column" : 2
101+ },
102+ "end" : {
103+ "line" : 5 ,
104+ "column" : 5
105+ }
106+ },
107+ "name" : " val"
108+ }
109+ }
110+ ],
111+ "typeParams" : " T extends string"
112+ },
113+ {
114+ "type" : " Text" ,
115+ "start" : 92 ,
116+ "end" : 94 ,
117+ "raw" : " \n\n " ,
118+ "data" : " \n\n "
119+ },
120+ {
121+ "type" : " SnippetBlock" ,
122+ "start" : 94 ,
123+ "end" : 192 ,
124+ "expression" : {
125+ "type" : " Identifier" ,
126+ "start" : 104 ,
127+ "end" : 119 ,
128+ "name" : " complex_generic"
129+ },
130+ "parameters" : [
131+ {
132+ "type" : " Identifier" ,
133+ "start" : 166 ,
134+ "end" : 172 ,
135+ "loc" : {
136+ "start" : {
137+ "line" : 8 ,
138+ "column" : 72
139+ },
140+ "end" : {
141+ "line" : 8 ,
142+ "column" : 78
143+ }
144+ },
145+ "name" : " val" ,
146+ "typeAnnotation" : {
147+ "type" : " TSTypeAnnotation" ,
148+ "start" : 169 ,
149+ "end" : 172 ,
150+ "loc" : {
151+ "start" : {
152+ "line" : 8 ,
153+ "column" : 75
154+ },
155+ "end" : {
156+ "line" : 8 ,
157+ "column" : 78
158+ }
159+ },
160+ "typeAnnotation" : {
161+ "type" : " TSTypeReference" ,
162+ "start" : 171 ,
163+ "end" : 172 ,
164+ "loc" : {
165+ "start" : {
166+ "line" : 8 ,
167+ "column" : 77
168+ },
169+ "end" : {
170+ "line" : 8 ,
171+ "column" : 78
172+ }
173+ },
174+ "typeName" : {
175+ "type" : " Identifier" ,
176+ "start" : 171 ,
177+ "end" : 172 ,
178+ "loc" : {
179+ "start" : {
180+ "line" : 8 ,
181+ "column" : 77
182+ },
183+ "end" : {
184+ "line" : 8 ,
185+ "column" : 78
186+ }
187+ },
188+ "name" : " T"
189+ }
190+ }
191+ }
192+ }
193+ ],
194+ "children" : [
195+ {
196+ "type" : " MustacheTag" ,
197+ "start" : 176 ,
198+ "end" : 181 ,
199+ "expression" : {
200+ "type" : " Identifier" ,
201+ "start" : 177 ,
202+ "end" : 180 ,
203+ "loc" : {
204+ "start" : {
205+ "line" : 9 ,
206+ "column" : 2
207+ },
208+ "end" : {
209+ "line" : 9 ,
210+ "column" : 5
211+ }
212+ },
213+ "name" : " val"
214+ }
215+ }
216+ ],
217+ "typeParams" : " T extends { bracket: \" <\" } | \" <\" | Set<\" <>\" >"
218+ }
219+ ]
220+ },
221+ "instance" : {
222+ "type" : " Script" ,
223+ "start" : 0 ,
224+ "end" : 28 ,
225+ "context" : " default" ,
226+ "content" : {
227+ "type" : " Program" ,
228+ "start" : 18 ,
229+ "end" : 19 ,
230+ "loc" : {
231+ "start" : {
232+ "line" : 1 ,
233+ "column" : 0
234+ },
235+ "end" : {
236+ "line" : 2 ,
237+ "column" : 0
238+ }
239+ },
240+ "body" : [],
241+ "sourceType" : " module"
242+ }
243+ }
244+ }
You can’t perform that action at this time.
0 commit comments