@@ -37,7 +37,7 @@ namespace ts {
3737
3838 // transform hooks
3939 onEmitNode : transform . emitNodeWithNotification ,
40- onSubstituteNode : transform . emitNodeWithSubstitution ,
40+ substituteNode : transform . substituteNode ,
4141
4242 // sourcemap hooks
4343 onEmitSourceMapOfNode : sourceMap . emitNodeWithSourceMap ,
@@ -198,7 +198,7 @@ namespace ts {
198198 onEmitNode,
199199 onEmitHelpers,
200200 onSetSourceFile,
201- onSubstituteNode ,
201+ substituteNode ,
202202 } = handlers ;
203203
204204 const newLine = getNewLineCharacter ( printerOptions ) ;
@@ -327,8 +327,8 @@ namespace ts {
327327 setWriter ( /*output*/ undefined ) ;
328328 }
329329
330- function emit ( node : Node , hint = EmitHint . Unspecified ) {
331- pipelineEmitWithNotification ( hint , node ) ;
330+ function emit ( node : Node ) {
331+ pipelineEmitWithNotification ( EmitHint . Unspecified , node ) ;
332332 }
333333
334334 function emitIdentifierName ( node : Identifier ) {
@@ -349,6 +349,7 @@ namespace ts {
349349 }
350350
351351 function pipelineEmitWithComments ( hint : EmitHint , node : Node ) {
352+ node = trySubstituteNode ( hint , node ) ;
352353 if ( emitNodeWithComments && hint !== EmitHint . SourceFile ) {
353354 emitNodeWithComments ( hint , node , pipelineEmitWithSourceMap ) ;
354355 }
@@ -359,16 +360,7 @@ namespace ts {
359360
360361 function pipelineEmitWithSourceMap ( hint : EmitHint , node : Node ) {
361362 if ( onEmitSourceMapOfNode && hint !== EmitHint . SourceFile && hint !== EmitHint . IdentifierName ) {
362- onEmitSourceMapOfNode ( hint , node , pipelineEmitWithSubstitution ) ;
363- }
364- else {
365- pipelineEmitWithSubstitution ( hint , node ) ;
366- }
367- }
368-
369- function pipelineEmitWithSubstitution ( hint : EmitHint , node : Node ) {
370- if ( onSubstituteNode ) {
371- onSubstituteNode ( hint , node , pipelineEmitWithHint ) ;
363+ onEmitSourceMapOfNode ( hint , node , pipelineEmitWithHint ) ;
372364 }
373365 else {
374366 pipelineEmitWithHint ( hint , node ) ;
@@ -634,7 +626,7 @@ namespace ts {
634626 // If the node is an expression, try to emit it as an expression with
635627 // substitution.
636628 if ( isExpression ( node ) ) {
637- return pipelineEmitWithSubstitution ( EmitHint . Expression , node ) ;
629+ return pipelineEmitExpression ( trySubstituteNode ( EmitHint . Expression , node ) ) ;
638630 }
639631 }
640632
@@ -731,6 +723,10 @@ namespace ts {
731723 }
732724 }
733725
726+ function trySubstituteNode ( hint : EmitHint , node : Node ) {
727+ return node && substituteNode && substituteNode ( hint , node ) || node ;
728+ }
729+
734730 function emitBodyIndirect ( node : Node , elements : NodeArray < Node > , emitCallback : ( node : Node ) => void ) : void {
735731 if ( emitBodyWithDetachedComments ) {
736732 emitBodyWithDetachedComments ( node , elements , emitCallback ) ;
0 commit comments