@@ -46,6 +46,11 @@ namespace ts {
4646 return visitFunctionExpression ( node as FunctionExpression ) ;
4747 case SyntaxKind . ArrowFunction :
4848 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 ) ;
4954 case SyntaxKind . Parameter :
5055 return visitParameter ( node as ParameterDeclaration ) ;
5156 default :
@@ -208,11 +213,6 @@ namespace ts {
208213 }
209214
210215 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-
216216 return setOriginalNode (
217217 createFunctionDeclaration (
218218 /*decorators*/ undefined ,
@@ -222,25 +222,21 @@ namespace ts {
222222 /*typeParameters*/ undefined ,
223223 visitNodes ( node . parameters , visitor , isParameter ) ,
224224 /*type*/ undefined ,
225- body ,
225+ transformFunctionBodyIfNeeded ( node ) ,
226226 /*location*/ node
227227 ) ,
228228 /*original*/ node ) ;
229229 }
230230
231231 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 ) ;
236232 const func = setOriginalNode (
237233 createArrowFunction (
238234 /*modifiers*/ undefined ,
239235 /*typeParameters*/ undefined ,
240236 visitNodes ( node . parameters , visitor , isParameter ) ,
241237 /*type*/ undefined ,
242238 node . equalsGreaterThanToken ,
243- body ,
239+ transformFunctionBodyIfNeeded ( node ) ,
244240 /*location*/ node
245241 ) ,
246242 /*original*/ node
@@ -250,10 +246,6 @@ namespace ts {
250246 }
251247
252248 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 ) ;
257249 return setOriginalNode (
258250 createFunctionExpression (
259251 /*modifiers*/ undefined ,
@@ -262,11 +254,62 @@ namespace ts {
262254 /*typeParameters*/ undefined ,
263255 visitNodes ( node . parameters , visitor , isParameter ) ,
264256 /*type*/ undefined ,
265- body ,
257+ transformFunctionBodyIfNeeded ( node ) ,
266258 /*location*/ node
267259 ) ,
268260 /*original*/ node
269261 ) ;
270262 }
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+ }
271314 }
272315}
0 commit comments