@@ -203,10 +203,8 @@ const _super = (function (geti, seti) {
203
203
204
204
const sourceMap = createSourceMapWriter ( host , writer ) ;
205
205
const {
206
- emitStart,
207
- emitEnd,
208
- emitTokenStart,
209
- emitTokenEnd
206
+ emitNodeWithSourceMap,
207
+ emitTokenWithSourceMap
210
208
} = sourceMap ;
211
209
212
210
const comments = createCommentWriter ( host , writer , sourceMap ) ;
@@ -244,10 +242,8 @@ const _super = (function (geti, seti) {
244
242
245
243
// Extract helpers from the result
246
244
const {
247
- isSubstitutionEnabled,
248
- isEmitNotificationEnabled,
249
- onSubstituteNode,
250
- onEmitNode
245
+ emitNodeWithSubstitution,
246
+ emitNodeWithNotification
251
247
} = transformed ;
252
248
253
249
performance . mark ( "beforePrint" ) ;
@@ -448,101 +444,6 @@ const _super = (function (geti, seti) {
448
444
emitNodeWithSubstitution ( node , /*isExpression*/ true , emitExpressionWorker ) ;
449
445
}
450
446
451
- /**
452
- * Emits a node with possible emit notification.
453
- */
454
- // TODO(rbuckton): Move this into transformer.ts
455
- function emitNodeWithNotification ( node : Node , emitCallback : ( node : Node ) => void ) {
456
- if ( node ) {
457
- if ( isEmitNotificationEnabled ( node ) ) {
458
- onEmitNode ( node , emitCallback ) ;
459
- }
460
- else {
461
- emitCallback ( node ) ;
462
- }
463
- }
464
- }
465
-
466
- /**
467
- * Emits a node with possible source maps.
468
- */
469
- // TODO(rbuckton): Move this into sourcemap.ts
470
- function emitNodeWithSourceMap ( node : Node , emitCallback : ( node : Node ) => void ) {
471
- if ( node ) {
472
- emitStart ( /*range*/ node , /*contextNode*/ node , shouldSkipLeadingSourceMapForNode , shouldSkipSourceMapForChildren , getSourceMapRange ) ;
473
- emitCallback ( node ) ;
474
- emitEnd ( /*range*/ node , /*contextNode*/ node , shouldSkipTrailingSourceMapForNode , shouldSkipSourceMapForChildren , getSourceMapRange ) ;
475
- }
476
- }
477
-
478
- /**
479
- * Determines whether to skip leading comment emit for a node.
480
- *
481
- * We do not emit comments for NotEmittedStatement nodes or any node that has
482
- * NodeEmitFlags.NoLeadingComments.
483
- *
484
- * @param node A Node.
485
- */
486
- // TODO(rbuckton): Move this into comments.ts
487
- function shouldSkipLeadingCommentsForNode ( node : Node ) {
488
- return isNotEmittedStatement ( node )
489
- || ( getEmitFlags ( node ) & EmitFlags . NoLeadingComments ) !== 0 ;
490
- }
491
-
492
- /**
493
- * Determines whether to skip source map emit for the start position of a node.
494
- *
495
- * We do not emit source maps for NotEmittedStatement nodes or any node that
496
- * has NodeEmitFlags.NoLeadingSourceMap.
497
- *
498
- * @param node A Node.
499
- */
500
- // TODO(rbuckton): Move this into sourcemap.ts
501
- function shouldSkipLeadingSourceMapForNode ( node : Node ) {
502
- return isNotEmittedStatement ( node )
503
- || ( getEmitFlags ( node ) & EmitFlags . NoLeadingSourceMap ) !== 0 ;
504
- }
505
-
506
- /**
507
- * Determines whether to skip source map emit for the end position of a node.
508
- *
509
- * We do not emit source maps for NotEmittedStatement nodes or any node that
510
- * has NodeEmitFlags.NoTrailingSourceMap.
511
- *
512
- * @param node A Node.
513
- */
514
- // TODO(rbuckton): Move this into sourcemap.ts
515
- function shouldSkipTrailingSourceMapForNode ( node : Node ) {
516
- return isNotEmittedStatement ( node )
517
- || ( getEmitFlags ( node ) & EmitFlags . NoTrailingSourceMap ) !== 0 ;
518
- }
519
-
520
- /**
521
- * Determines whether to skip source map emit for a node and its children.
522
- *
523
- * We do not emit source maps for a node that has NodeEmitFlags.NoNestedSourceMaps.
524
- */
525
- // TODO(rbuckton): Move this into sourcemap.ts
526
- function shouldSkipSourceMapForChildren ( node : Node ) {
527
- return ( getEmitFlags ( node ) & EmitFlags . NoNestedSourceMaps ) !== 0 ;
528
- }
529
-
530
- /**
531
- * Emits a node with possible substitution.
532
- */
533
- // TODO(rbuckton): Move this into transformer.ts
534
- function emitNodeWithSubstitution ( node : Node , isExpression : boolean , emitCallback : ( node : Node ) => void ) {
535
- if ( isSubstitutionEnabled ( node ) && ( getEmitFlags ( node ) & EmitFlags . NoSubstitution ) === 0 ) {
536
- const substitute = onSubstituteNode ( node , isExpression ) ;
537
- if ( substitute !== node ) {
538
- emitCallback ( substitute ) ;
539
- return ;
540
- }
541
- }
542
-
543
- emitCallback ( node ) ;
544
- }
545
-
546
447
/**
547
448
* Emits a node.
548
449
*
@@ -585,7 +486,7 @@ const _super = (function (geti, seti) {
585
486
case SyntaxKind . StringKeyword :
586
487
case SyntaxKind . SymbolKeyword :
587
488
case SyntaxKind . GlobalKeyword :
588
- return writeTokenNode ( node ) ;
489
+ return emitTokenNode ( node ) ;
589
490
590
491
// Parse tree nodes
591
492
@@ -832,7 +733,7 @@ const _super = (function (geti, seti) {
832
733
case SyntaxKind . SuperKeyword :
833
734
case SyntaxKind . TrueKeyword :
834
735
case SyntaxKind . ThisKeyword :
835
- return writeTokenNode ( node ) ;
736
+ return emitTokenNode ( node ) ;
836
737
837
738
// Expressions
838
739
case SyntaxKind . ArrayLiteralExpression :
@@ -2129,7 +2030,7 @@ const _super = (function (geti, seti) {
2129
2030
// "comment1" is not considered to be leading comment for node.initializer
2130
2031
// but rather a trailing comment on the previous node.
2131
2032
const initializer = node . initializer ;
2132
- if ( ! shouldSkipLeadingCommentsForNode ( initializer ) ) {
2033
+ if ( ( getEmitFlags ( initializer ) & EmitFlags . NoLeadingComments ) === 0 ) {
2133
2034
const commentRange = getCommentRange ( initializer ) ;
2134
2035
emitTrailingCommentsOfPosition ( commentRange . pos ) ;
2135
2036
}
@@ -2537,17 +2438,7 @@ const _super = (function (geti, seti) {
2537
2438
}
2538
2439
2539
2440
function writeToken ( token : SyntaxKind , pos : number , contextNode ?: Node ) {
2540
- const tokenStartPos = emitTokenStart ( token , pos , contextNode , shouldSkipLeadingSourceMapForToken , getTokenSourceMapRange ) ;
2541
- const tokenEndPos = writeTokenText ( token , tokenStartPos ) ;
2542
- return emitTokenEnd ( token , tokenEndPos , contextNode , shouldSkipTrailingSourceMapForToken , getTokenSourceMapRange ) ;
2543
- }
2544
-
2545
- function shouldSkipLeadingSourceMapForToken ( contextNode : Node ) {
2546
- return ( getEmitFlags ( contextNode ) & EmitFlags . NoTokenLeadingSourceMaps ) !== 0 ;
2547
- }
2548
-
2549
- function shouldSkipTrailingSourceMapForToken ( contextNode : Node ) {
2550
- return ( getEmitFlags ( contextNode ) & EmitFlags . NoTokenTrailingSourceMaps ) !== 0 ;
2441
+ return emitTokenWithSourceMap ( contextNode , token , pos , writeTokenText ) ;
2551
2442
}
2552
2443
2553
2444
function writeTokenText ( token : SyntaxKind , pos ?: number ) {
@@ -2556,12 +2447,12 @@ const _super = (function (geti, seti) {
2556
2447
return positionIsSynthesized ( pos ) ? - 1 : pos + tokenString . length ;
2557
2448
}
2558
2449
2559
- function writeTokenNode ( node : Node ) {
2560
- if ( node ) {
2561
- emitStart ( /*range*/ node , /*contextNode*/ node , shouldSkipLeadingSourceMapForNode , shouldSkipSourceMapForChildren , getSourceMapRange ) ;
2562
- writeTokenText ( node . kind ) ;
2563
- emitEnd ( /*range*/ node , /*contextNode*/ node , shouldSkipTrailingSourceMapForNode , shouldSkipSourceMapForChildren , getSourceMapRange ) ;
2564
- }
2450
+ function emitTokenNode ( node : Node ) {
2451
+ emitNodeWithSourceMap ( node , emitTokenNodeWorker ) ;
2452
+ }
2453
+
2454
+ function emitTokenNodeWorker ( node : Node ) {
2455
+ writeTokenText ( node . kind ) ;
2565
2456
}
2566
2457
2567
2458
function increaseIndentIf ( value : boolean , valueToWriteWhenNotIndenting ?: string ) {
0 commit comments