@@ -177,25 +177,7 @@ function walkIdentifiers(
177
177
}
178
178
}
179
179
else if ( ts . isArrowFunction ( node ) || ts . isFunctionExpression ( node ) ) {
180
-
181
- const functionArgs : string [ ] = [ ] ;
182
-
183
- for ( const param of node . parameters ) {
184
- collectVars ( ts , param . name , ast , functionArgs ) ;
185
- if ( param . type ) {
186
- walkIdentifiers ( ts , param . type , ast , cb , ctx , blockVars , false ) ;
187
- }
188
- }
189
-
190
- for ( const varName of functionArgs ) {
191
- ctx . addLocalVariable ( varName ) ;
192
- }
193
-
194
- walkIdentifiers ( ts , node . body , ast , cb , ctx , blockVars , false ) ;
195
-
196
- for ( const varName of functionArgs ) {
197
- ctx . removeLocalVariable ( varName ) ;
198
- }
180
+ processFunction ( ts , node , ast , cb , ctx ) ;
199
181
}
200
182
else if ( ts . isObjectLiteralExpression ( node ) ) {
201
183
for ( const prop of node . properties ) {
@@ -215,6 +197,10 @@ function walkIdentifiers(
215
197
// TODO: cannot report "Spread types may only be created from object types.ts(2698)"
216
198
walkIdentifiers ( ts , prop . expression , ast , cb , ctx , blockVars , false ) ;
217
199
}
200
+ // fix https://github.com/vuejs/language-tools/issues/4604
201
+ else if ( ts . isFunctionLike ( prop ) && prop . body ) {
202
+ processFunction ( ts , prop , ast , cb , ctx ) ;
203
+ }
218
204
}
219
205
}
220
206
else if ( ts . isTypeReferenceNode ( node ) ) {
@@ -242,6 +228,31 @@ function walkIdentifiers(
242
228
}
243
229
}
244
230
231
+ function processFunction (
232
+ ts : typeof import ( 'typescript' ) ,
233
+ node : ts . ArrowFunction | ts . FunctionExpression | ts . AccessorDeclaration | ts . MethodDeclaration ,
234
+ ast : ts . SourceFile ,
235
+ cb : ( varNode : ts . Identifier , isShorthand : boolean ) => void ,
236
+ ctx : TemplateCodegenContext
237
+ ) {
238
+ const functionArgs : string [ ] = [ ] ;
239
+ for ( const param of node . parameters ) {
240
+ collectVars ( ts , param . name , ast , functionArgs ) ;
241
+ if ( param . type ) {
242
+ walkIdentifiers ( ts , param . type , ast , cb , ctx ) ;
243
+ }
244
+ }
245
+ for ( const varName of functionArgs ) {
246
+ ctx . addLocalVariable ( varName ) ;
247
+ }
248
+ if ( node . body ) {
249
+ walkIdentifiers ( ts , node . body , ast , cb , ctx ) ;
250
+ }
251
+ for ( const varName of functionArgs ) {
252
+ ctx . removeLocalVariable ( varName ) ;
253
+ }
254
+ }
255
+
245
256
function walkIdentifiersInTypeReference (
246
257
ts : typeof import ( 'typescript' ) ,
247
258
node : ts . Node ,
0 commit comments