@@ -42,19 +42,20 @@ export function handleSnippet(
42
42
}
43
43
) ;
44
44
45
+ const lastParameter = snippetBlock . parameters ?. at ( - 1 ) ;
46
+
45
47
const startEnd =
46
48
str . original . indexOf (
47
49
'}' ,
48
- // context was the first iteration in a .next release, remove at some point
49
- snippetBlock . parameters ?. at ( - 1 ) ?. end || snippetBlock . expression . end
50
+ lastParameter ?. typeAnnotation ?. end ?? lastParameter ?. end ?? snippetBlock . expression . end
50
51
) + 1 ;
51
52
52
53
if ( isImplicitProp ) {
53
54
str . overwrite ( snippetBlock . start , snippetBlock . expression . start , '' , { contentOnly : true } ) ;
54
55
const transforms : TransformationArray = [ '(' ] ;
55
56
if ( snippetBlock . parameters ?. length ) {
56
- const start = snippetBlock . parameters ?. [ 0 ] . start ;
57
- const end = snippetBlock . parameters . at ( - 1 ) . end ;
57
+ const start = snippetBlock . parameters [ 0 ] . start ;
58
+ const end = lastParameter . typeAnnotation ?. end ?? lastParameter . end ;
58
59
transforms . push ( [ start , end ] ) ;
59
60
str . overwrite ( snippetBlock . expression . end , start , '' , {
60
61
contentOnly : true
@@ -73,15 +74,23 @@ export function handleSnippet(
73
74
let generic = '' ;
74
75
if ( snippetBlock . parameters ?. length ) {
75
76
generic = `<[${ snippetBlock . parameters
76
- . map ( ( p ) =>
77
- p . typeAnnotation ?. typeAnnotation
77
+ . map ( ( p ) => {
78
+ let typeAnnotation = p . typeAnnotation ;
79
+ if ( ! typeAnnotation && p . type === 'AssignmentPattern' ) {
80
+ typeAnnotation = p . left ?. typeAnnotation ;
81
+ if ( ! typeAnnotation ) {
82
+ typeAnnotation = p . right ?. typeAnnotation ;
83
+ }
84
+ }
85
+ if ( ! typeAnnotation ) return 'any' ;
86
+ return typeAnnotation . typeAnnotation
78
87
? str . original . slice (
79
- p . typeAnnotation . typeAnnotation . start ,
80
- p . typeAnnotation . typeAnnotation . end
88
+ typeAnnotation . typeAnnotation . start ,
89
+ typeAnnotation . typeAnnotation . end
81
90
)
82
91
: // slap any on to it to silence "implicit any" errors; JSDoc people can't add types to snippets
83
- 'any'
84
- )
92
+ 'any' ;
93
+ } )
85
94
. join ( ', ' ) } ]>`;
86
95
}
87
96
@@ -94,7 +103,7 @@ export function handleSnippet(
94
103
95
104
if ( snippetBlock . parameters ?. length ) {
96
105
const start = snippetBlock . parameters [ 0 ] . start ;
97
- const end = snippetBlock . parameters . at ( - 1 ) . end ;
106
+ const end = lastParameter . typeAnnotation ?. end ?? lastParameter . end ;
98
107
transforms . push ( [ start , end ] ) ;
99
108
}
100
109
0 commit comments