@@ -43,17 +43,26 @@ export function handleSnippet(
43
43
) ;
44
44
45
45
const startEnd =
46
- str . original . indexOf ( '}' , snippetBlock . context ?. end || snippetBlock . expression . end ) + 1 ;
46
+ str . original . indexOf (
47
+ '}' ,
48
+ // context was the first iteration in a .next release, remove at some point
49
+ snippetBlock . context ?. end ||
50
+ snippetBlock . parameters ?. at ( - 1 ) ?. end ||
51
+ snippetBlock . expression . end
52
+ ) + 1 ;
47
53
48
54
if ( isImplicitProp ) {
49
55
str . overwrite ( snippetBlock . start , snippetBlock . expression . start , '' , { contentOnly : true } ) ;
50
56
const transforms : TransformationArray = [ '(' ] ;
51
- if ( snippetBlock . context ) {
52
- transforms . push ( [ snippetBlock . context . start , snippetBlock . context . end ] ) ;
53
- str . overwrite ( snippetBlock . expression . end , snippetBlock . context . start , '' , {
57
+ if ( snippetBlock . context || snippetBlock . parameters ?. length ) {
58
+ // context was the first iteration in a .next release, remove at some point
59
+ const start = snippetBlock . context ?. start || snippetBlock . parameters ?. [ 0 ] . start ;
60
+ const end = snippetBlock . context ?. end || snippetBlock . parameters . at ( - 1 ) . end ;
61
+ transforms . push ( [ start , end ] ) ;
62
+ str . overwrite ( snippetBlock . expression . end , start , '' , {
54
63
contentOnly : true
55
64
} ) ;
56
- str . overwrite ( snippetBlock . context . end , startEnd , '' , { contentOnly : true } ) ;
65
+ str . overwrite ( end , startEnd , '' , { contentOnly : true } ) ;
57
66
} else {
58
67
str . overwrite ( snippetBlock . expression . end , startEnd , '' , { contentOnly : true } ) ;
59
68
}
@@ -64,15 +73,27 @@ export function handleSnippet(
64
73
transforms
65
74
) ;
66
75
} else {
67
- const generic = snippetBlock . context
68
- ? snippetBlock . context . typeAnnotation
76
+ let generic = '' ;
77
+ // context was the first iteration in a .next release, remove at some point
78
+ if ( snippetBlock . context ) {
79
+ generic = snippetBlock . context . typeAnnotation
69
80
? `<${ str . original . slice (
70
- snippetBlock . context . typeAnnotation . start ,
81
+ snippetBlock . context . typeAnnotation . start + 1 ,
71
82
snippetBlock . context . typeAnnotation . end
72
83
) } >`
73
84
: // slap any on to it to silence "implicit any" errors; JSDoc people can't add types to snippets
74
- '<any>'
75
- : '' ;
85
+ '<any>' ;
86
+ } else if ( snippetBlock . parameters ?. length ) {
87
+ generic = `<[${ snippetBlock . parameters
88
+ . map ( ( p ) =>
89
+ p . typeAnnotation
90
+ ? str . original . slice ( p . typeAnnotation . start + 1 , p . typeAnnotation . end )
91
+ : // slap any on to it to silence "implicit any" errors; JSDoc people can't add types to snippets
92
+ 'any'
93
+ )
94
+ . join ( ', ' ) } ]>`;
95
+ }
96
+
76
97
const typeAnnotation = surroundWithIgnoreComments ( `: import('svelte').Snippet${ generic } ` ) ;
77
98
const transforms : TransformationArray = [
78
99
'var ' ,
0 commit comments