@@ -46,6 +46,11 @@ namespace ts {
46
46
return visitFunctionExpression ( node as FunctionExpression ) ;
47
47
case SyntaxKind . ArrowFunction :
48
48
return visitArrowFunction ( node as ArrowFunction ) ;
49
+ case SyntaxKind . MethodDeclaration :
50
+ return visitMethodDeclaration ( node as MethodDeclaration ) ;
51
+ case SyntaxKind . GetAccessor :
52
+ case SyntaxKind . SetAccessor :
53
+ return visitAccessorDeclaration ( node as AccessorDeclaration ) ;
49
54
case SyntaxKind . Parameter :
50
55
return visitParameter ( node as ParameterDeclaration ) ;
51
56
default :
@@ -208,11 +213,6 @@ namespace ts {
208
213
}
209
214
210
215
function visitFunctionDeclaration ( node : FunctionDeclaration ) : FunctionDeclaration {
211
- const hasRest = forEach ( node . parameters , isObjectRestParameter ) ;
212
- const body = hasRest ?
213
- transformFunctionBody ( node , visitor , currentSourceFile , context , noop , /*convertObjectRest*/ true ) as Block :
214
- visitEachChild ( node . body , visitor , context ) ;
215
-
216
216
return setOriginalNode (
217
217
createFunctionDeclaration (
218
218
/*decorators*/ undefined ,
@@ -222,25 +222,21 @@ namespace ts {
222
222
/*typeParameters*/ undefined ,
223
223
visitNodes ( node . parameters , visitor , isParameter ) ,
224
224
/*type*/ undefined ,
225
- body ,
225
+ transformFunctionBodyIfNeeded ( node ) ,
226
226
/*location*/ node
227
227
) ,
228
228
/*original*/ node ) ;
229
229
}
230
230
231
231
function visitArrowFunction ( node : ArrowFunction ) {
232
- const hasRest = forEach ( node . parameters , isObjectRestParameter ) ;
233
- const body = hasRest ?
234
- transformFunctionBody ( node , visitor , currentSourceFile , context , noop , /*convertObjectRest*/ true ) as Block :
235
- visitEachChild ( node . body , visitor , context ) ;
236
232
const func = setOriginalNode (
237
233
createArrowFunction (
238
234
/*modifiers*/ undefined ,
239
235
/*typeParameters*/ undefined ,
240
236
visitNodes ( node . parameters , visitor , isParameter ) ,
241
237
/*type*/ undefined ,
242
238
node . equalsGreaterThanToken ,
243
- body ,
239
+ transformFunctionBodyIfNeeded ( node ) ,
244
240
/*location*/ node
245
241
) ,
246
242
/*original*/ node
@@ -250,10 +246,6 @@ namespace ts {
250
246
}
251
247
252
248
function visitFunctionExpression ( node : FunctionExpression ) : Expression {
253
- const hasRest = forEach ( node . parameters , isObjectRestParameter ) ;
254
- const body = hasRest ?
255
- transformFunctionBody ( node , visitor , currentSourceFile , context , noop , /*convertObjectRest*/ true ) as Block :
256
- visitEachChild ( node . body , visitor , context ) ;
257
249
return setOriginalNode (
258
250
createFunctionExpression (
259
251
/*modifiers*/ undefined ,
@@ -262,11 +254,62 @@ namespace ts {
262
254
/*typeParameters*/ undefined ,
263
255
visitNodes ( node . parameters , visitor , isParameter ) ,
264
256
/*type*/ undefined ,
265
- body ,
257
+ transformFunctionBodyIfNeeded ( node ) ,
266
258
/*location*/ node
267
259
) ,
268
260
/*original*/ node
269
261
) ;
270
262
}
263
+
264
+ function visitMethodDeclaration ( node : MethodDeclaration ) : MethodDeclaration {
265
+ return setOriginalNode (
266
+ createMethod (
267
+ /*decorators*/ undefined ,
268
+ node . modifiers ,
269
+ node . asteriskToken ,
270
+ node . name ,
271
+ /*typeParameters*/ undefined ,
272
+ visitNodes ( node . parameters , visitor , isParameter ) ,
273
+ /*type*/ undefined ,
274
+ transformFunctionBodyIfNeeded ( node ) ,
275
+ /*location*/ node
276
+ ) ,
277
+ /*original*/ node ) ;
278
+ }
279
+
280
+ function visitAccessorDeclaration ( node : AccessorDeclaration ) : AccessorDeclaration {
281
+ if ( node . kind === SyntaxKind . GetAccessor ) {
282
+ return setOriginalNode (
283
+ createGetAccessor (
284
+ /*decorators*/ undefined ,
285
+ node . modifiers ,
286
+ node . name ,
287
+ visitNodes ( node . parameters , visitor , isParameter ) ,
288
+ /*type*/ undefined ,
289
+ transformFunctionBodyIfNeeded ( node ) ,
290
+ /*location*/ node
291
+ ) ,
292
+ /*original*/ node ) ;
293
+ }
294
+ else {
295
+ return setOriginalNode (
296
+ createSetAccessor (
297
+ /*decorators*/ undefined ,
298
+ node . modifiers ,
299
+ node . name ,
300
+ visitNodes ( node . parameters , visitor , isParameter ) ,
301
+ transformFunctionBodyIfNeeded ( node ) ,
302
+ /*location*/ node
303
+ ) ,
304
+ /*original*/ node ) ;
305
+ }
306
+ }
307
+
308
+ function transformFunctionBodyIfNeeded ( node : FunctionLikeDeclaration ) : Block {
309
+ const hasRest = forEach ( node . parameters , isObjectRestParameter ) ;
310
+ return hasRest ?
311
+ transformFunctionBody ( node , visitor , currentSourceFile , context , noop , /*convertObjectRest*/ true ) :
312
+ visitEachChild ( node . body , visitor , context ) as Block ;
313
+ }
271
314
}
272
315
}
0 commit comments