@@ -1386,37 +1386,30 @@ namespace ts {
1386
1386
*/
1387
1387
/* @internal */
1388
1388
export function suppressLeadingAndTrailingTrivia ( node : Node ) {
1389
- Debug . assert ( node !== undefined ) ;
1390
-
1391
- suppressLeading ( node ) ;
1392
- suppressTrailing ( node ) ;
1393
-
1394
- function suppressLeading ( node : Node ) {
1395
- addEmitFlags ( node , EmitFlags . NoLeadingComments ) ;
1396
-
1397
- const firstChild = forEachChild ( node , child => child ) ;
1398
- if ( firstChild ) {
1399
- suppressLeading ( firstChild ) ;
1400
- }
1389
+ Debug . assertDefined ( node ) ;
1390
+ suppress ( node , EmitFlags . NoLeadingComments , getFirstChild ) ;
1391
+ suppress ( node , EmitFlags . NoTrailingComments , getLastChild ) ;
1392
+ function suppress ( node : Node , flag : EmitFlags , getChild : ( n : Node ) => Node ) {
1393
+ addEmitFlags ( node , flag ) ;
1394
+ const child = getChild ( node ) ;
1395
+ if ( child ) suppress ( child , flag , getChild ) ;
1401
1396
}
1397
+ }
1402
1398
1403
- function suppressTrailing ( node : Node ) {
1404
- addEmitFlags ( node , EmitFlags . NoTrailingComments ) ;
1405
-
1406
- let lastChild : Node ;
1407
- forEachChild (
1408
- node ,
1409
- child => ( lastChild = child , undefined ) ,
1410
- children => {
1411
- // As an optimization, jump straight to the end of the list.
1412
- if ( children . length ) {
1413
- lastChild = last ( children ) ;
1414
- }
1415
- return undefined ;
1416
- } ) ;
1417
- if ( lastChild ) {
1418
- suppressTrailing ( lastChild ) ;
1419
- }
1420
- }
1399
+ function getFirstChild ( node : Node ) : Node | undefined {
1400
+ return node . forEachChild ( child => child ) ;
1401
+ }
1402
+
1403
+ function getLastChild ( node : Node ) : Node | undefined {
1404
+ let lastChild : Node | undefined ;
1405
+ node . forEachChild (
1406
+ child => { lastChild = child ; } ,
1407
+ children => {
1408
+ // As an optimization, jump straight to the end of the list.
1409
+ if ( children . length ) {
1410
+ lastChild = last ( children ) ;
1411
+ }
1412
+ } ) ;
1413
+ return lastChild ;
1421
1414
}
1422
1415
}
0 commit comments