@@ -2633,7 +2633,8 @@ namespace ts {
2633
2633
// If needed, we should emit a variable declaration for the enum. If we emit
2634
2634
// a leading variable declaration, we should not emit leading comments for the
2635
2635
// enum body.
2636
- if ( addVarForEnumOrModuleDeclaration ( statements , node ) ) {
2636
+ const varAdded = addVarForEnumOrModuleDeclaration ( statements , node ) ;
2637
+ if ( varAdded ) {
2637
2638
// We should still emit the comments if we are emitting a system module.
2638
2639
if ( moduleKind !== ModuleKind . System || currentLexicalScope !== currentSourceFile ) {
2639
2640
emitFlags |= EmitFlags . NoLeadingComments ;
@@ -2691,8 +2692,13 @@ namespace ts {
2691
2692
) ;
2692
2693
2693
2694
setOriginalNode ( enumStatement , node ) ;
2695
+ if ( varAdded ) {
2696
+ // If a variable was added, synthetic comments are mitted on it, not on the moduleStatement.
2697
+ setSyntheticLeadingComments ( enumStatement , undefined ) ;
2698
+ setSyntheticTrailingComments ( enumStatement , undefined ) ;
2699
+ }
2694
2700
setTextRange ( enumStatement , node ) ;
2695
- setEmitFlags ( enumStatement , emitFlags ) ;
2701
+ addEmitFlags ( enumStatement , emitFlags ) ;
2696
2702
statements . push ( enumStatement ) ;
2697
2703
2698
2704
// Add a DeclarationMarker for the enum to preserve trailing comments and mark
@@ -2882,7 +2888,7 @@ namespace ts {
2882
2888
// })(m1 || (m1 = {})); // trailing comment module
2883
2889
//
2884
2890
setCommentRange ( statement , node ) ;
2885
- setEmitFlags ( statement , EmitFlags . NoTrailingComments | EmitFlags . HasEndOfDeclarationMarker ) ;
2891
+ addEmitFlags ( statement , EmitFlags . NoTrailingComments | EmitFlags . HasEndOfDeclarationMarker ) ;
2886
2892
statements . push ( statement ) ;
2887
2893
return true ;
2888
2894
}
@@ -2922,7 +2928,8 @@ namespace ts {
2922
2928
// If needed, we should emit a variable declaration for the module. If we emit
2923
2929
// a leading variable declaration, we should not emit leading comments for the
2924
2930
// module body.
2925
- if ( addVarForEnumOrModuleDeclaration ( statements , node ) ) {
2931
+ const varAdded = addVarForEnumOrModuleDeclaration ( statements , node ) ;
2932
+ if ( varAdded ) {
2926
2933
// We should still emit the comments if we are emitting a system module.
2927
2934
if ( moduleKind !== ModuleKind . System || currentLexicalScope !== currentSourceFile ) {
2928
2935
emitFlags |= EmitFlags . NoLeadingComments ;
@@ -2979,8 +2986,13 @@ namespace ts {
2979
2986
) ;
2980
2987
2981
2988
setOriginalNode ( moduleStatement , node ) ;
2989
+ if ( varAdded ) {
2990
+ // If a variable was added, synthetic comments are mitted on it, not on the moduleStatement.
2991
+ setSyntheticLeadingComments ( moduleStatement , undefined ) ;
2992
+ setSyntheticTrailingComments ( moduleStatement , undefined ) ;
2993
+ }
2982
2994
setTextRange ( moduleStatement , node ) ;
2983
- setEmitFlags ( moduleStatement , emitFlags ) ;
2995
+ addEmitFlags ( moduleStatement , emitFlags ) ;
2984
2996
statements . push ( moduleStatement ) ;
2985
2997
2986
2998
// Add a DeclarationMarker for the namespace to preserve trailing comments and mark
0 commit comments