@@ -163,7 +163,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
163
163
let writeComment = writeCommentRange ;
164
164
165
165
/** Emit a node */
166
- let emit = emitNodeWithoutSourceMap ;
166
+ let emit = emitNodeWithCommentsAndWithoutSourcemap ;
167
167
168
168
/** Called just before starting emit of a node */
169
169
let emitStart = function ( node : Node ) { } ;
@@ -687,9 +687,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
687
687
}
688
688
}
689
689
}
690
+
691
+ function emitNodeWithCommentsAndWithSourcemap ( node : Node ) {
692
+ emitNodeConsideringCommentsOption ( node , emitNodeWithSourceMap ) ;
693
+ }
690
694
691
695
writeEmittedFiles = writeJavaScriptAndSourceMapFile ;
692
- emit = emitNodeWithSourceMap ;
696
+ emit = emitNodeWithCommentsAndWithSourcemap ;
693
697
emitStart = recordEmitNodeStartSpan ;
694
698
emitEnd = recordEmitNodeEndSpan ;
695
699
emitToken = writeTextWithSpanRecord ;
@@ -2096,7 +2100,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
2096
2100
}
2097
2101
2098
2102
write ( "." ) ;
2099
- emitNodeWithoutSourceMap ( node . right ) ;
2103
+ emit ( node . right ) ;
2100
2104
}
2101
2105
2102
2106
function emitEntityNameAsExpression ( node : EntityName , useFallback : boolean ) {
@@ -2788,7 +2792,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
2788
2792
emitNodeWithoutSourceMap ( counter ) ;
2789
2793
write ( " < " ) ;
2790
2794
2791
- emitNodeWithoutSourceMap ( rhsReference ) ;
2795
+ emitNodeWithCommentsAndWithoutSourcemap ( rhsReference ) ;
2792
2796
write ( ".length" ) ;
2793
2797
2794
2798
emitEnd ( node . initializer ) ;
@@ -2823,7 +2827,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
2823
2827
else {
2824
2828
// The following call does not include the initializer, so we have
2825
2829
// to emit it separately.
2826
- emitNodeWithoutSourceMap ( declaration ) ;
2830
+ emitNodeWithCommentsAndWithoutSourcemap ( declaration ) ;
2827
2831
write ( " = " ) ;
2828
2832
emitNodeWithoutSourceMap ( rhsIterationValue ) ;
2829
2833
}
@@ -2846,7 +2850,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
2846
2850
emitDestructuring ( assignmentExpression , /*isAssignmentExpressionStatement*/ true , /*value*/ undefined ) ;
2847
2851
}
2848
2852
else {
2849
- emitNodeWithoutSourceMap ( assignmentExpression ) ;
2853
+ emitNodeWithCommentsAndWithoutSourcemap ( assignmentExpression ) ;
2850
2854
}
2851
2855
}
2852
2856
emitEnd ( node . initializer ) ;
@@ -3002,7 +3006,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
3002
3006
write ( "exports." ) ;
3003
3007
}
3004
3008
}
3005
- emitNodeWithoutSourceMap ( node . name ) ;
3009
+ emitNodeWithCommentsAndWithoutSourcemap ( node . name ) ;
3006
3010
emitEnd ( node . name ) ;
3007
3011
}
3008
3012
@@ -3048,7 +3052,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
3048
3052
write ( "default" ) ;
3049
3053
}
3050
3054
else {
3051
- emitNodeWithoutSourceMap ( node . name ) ;
3055
+ emitNodeWithCommentsAndWithoutSourcemap ( node . name ) ;
3052
3056
}
3053
3057
write ( `", ` ) ;
3054
3058
emitDeclarationName ( node ) ;
@@ -3082,7 +3086,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
3082
3086
if ( compilerOptions . module === ModuleKind . System ) {
3083
3087
emitStart ( specifier . name ) ;
3084
3088
write ( `${ exportFunctionForFile } ("` ) ;
3085
- emitNodeWithoutSourceMap ( specifier . name ) ;
3089
+ emitNodeWithCommentsAndWithoutSourcemap ( specifier . name ) ;
3086
3090
write ( `", ` ) ;
3087
3091
emitExpressionIdentifier ( name ) ;
3088
3092
write ( ")" ) ;
@@ -3092,7 +3096,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
3092
3096
emitStart ( specifier . name ) ;
3093
3097
emitContainingModuleName ( specifier ) ;
3094
3098
write ( "." ) ;
3095
- emitNodeWithoutSourceMap ( specifier . name ) ;
3099
+ emitNodeWithCommentsAndWithoutSourcemap ( specifier . name ) ;
3096
3100
emitEnd ( specifier . name ) ;
3097
3101
write ( " = " ) ;
3098
3102
emitExpressionIdentifier ( name ) ;
@@ -3139,7 +3143,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
3139
3143
3140
3144
if ( exportChanged ) {
3141
3145
write ( `${ exportFunctionForFile } ("` ) ;
3142
- emitNodeWithoutSourceMap ( name ) ;
3146
+ emitNodeWithCommentsAndWithoutSourcemap ( name ) ;
3143
3147
write ( `", ` ) ;
3144
3148
}
3145
3149
@@ -3371,7 +3375,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
3371
3375
3372
3376
if ( exportChanged ) {
3373
3377
write ( `${ exportFunctionForFile } ("` ) ;
3374
- emitNodeWithoutSourceMap ( node . name ) ;
3378
+ emitNodeWithCommentsAndWithoutSourcemap ( node . name ) ;
3375
3379
write ( `", ` ) ;
3376
3380
}
3377
3381
@@ -3527,9 +3531,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
3527
3531
emitEnd ( parameter ) ;
3528
3532
write ( " { " ) ;
3529
3533
emitStart ( parameter ) ;
3530
- emitNodeWithoutSourceMap ( paramName ) ;
3534
+ emitNodeWithCommentsAndWithoutSourcemap ( paramName ) ;
3531
3535
write ( " = " ) ;
3532
- emitNodeWithoutSourceMap ( initializer ) ;
3536
+ emitNodeWithCommentsAndWithoutSourcemap ( initializer ) ;
3533
3537
emitEnd ( parameter ) ;
3534
3538
write ( "; }" ) ;
3535
3539
}
@@ -3552,7 +3556,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
3552
3556
emitLeadingComments ( restParam ) ;
3553
3557
emitStart ( restParam ) ;
3554
3558
write ( "var " ) ;
3555
- emitNodeWithoutSourceMap ( restParam . name ) ;
3559
+ emitNodeWithCommentsAndWithoutSourcemap ( restParam . name ) ;
3556
3560
write ( " = [];" ) ;
3557
3561
emitEnd ( restParam ) ;
3558
3562
emitTrailingComments ( restParam ) ;
@@ -3573,7 +3577,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
3573
3577
increaseIndent ( ) ;
3574
3578
writeLine ( ) ;
3575
3579
emitStart ( restParam ) ;
3576
- emitNodeWithoutSourceMap ( restParam . name ) ;
3580
+ emitNodeWithCommentsAndWithoutSourcemap ( restParam . name ) ;
3577
3581
write ( "[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];" ) ;
3578
3582
emitEnd ( restParam ) ;
3579
3583
decreaseIndent ( ) ;
@@ -3594,7 +3598,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
3594
3598
3595
3599
function emitDeclarationName ( node : Declaration ) {
3596
3600
if ( node . name ) {
3597
- emitNodeWithoutSourceMap ( node . name ) ;
3601
+ emitNodeWithCommentsAndWithoutSourcemap ( node . name ) ;
3598
3602
}
3599
3603
else {
3600
3604
write ( getGeneratedNameForNode ( node ) ) ;
@@ -3622,6 +3626,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
3622
3626
emitLeadingComments ( node ) ;
3623
3627
}
3624
3628
3629
+ emitStart ( node ) ;
3625
3630
// For targeting below es6, emit functions-like declaration including arrow function using function keyword.
3626
3631
// When targeting ES6, emit arrow function natively in ES6 by omitting function keyword and using fat arrow instead
3627
3632
if ( ! shouldEmitAsArrowFunction ( node ) ) {
@@ -3647,6 +3652,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
3647
3652
if ( languageVersion < ScriptTarget . ES6 && node . kind === SyntaxKind . FunctionDeclaration && node . parent === currentSourceFile && node . name ) {
3648
3653
emitExportMemberAssignments ( ( < FunctionDeclaration > node ) . name ) ;
3649
3654
}
3655
+
3656
+ emitEnd ( node ) ;
3650
3657
if ( node . kind !== SyntaxKind . MethodDeclaration && node . kind !== SyntaxKind . MethodSignature ) {
3651
3658
emitTrailingComments ( node ) ;
3652
3659
}
@@ -4002,18 +4009,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
4002
4009
}
4003
4010
4004
4011
function emitMemberAccessForPropertyName ( memberName : DeclarationName ) {
4005
- // TODO: (jfreeman,drosen): comment on why this is emitNodeWithoutSourceMap instead of emit here.
4012
+ // This does not emit source map because it is emitted by caller as caller
4013
+ // is aware how the property name changes to the property access
4014
+ // eg. public x = 10; becomes this.x and static x = 10 becomes className.x
4006
4015
if ( memberName . kind === SyntaxKind . StringLiteral || memberName . kind === SyntaxKind . NumericLiteral ) {
4007
4016
write ( "[" ) ;
4008
- emitNodeWithoutSourceMap ( memberName ) ;
4017
+ emitNodeWithCommentsAndWithoutSourcemap ( memberName ) ;
4009
4018
write ( "]" ) ;
4010
4019
}
4011
4020
else if ( memberName . kind === SyntaxKind . ComputedPropertyName ) {
4012
4021
emitComputedPropertyName ( < ComputedPropertyName > memberName ) ;
4013
4022
}
4014
4023
else {
4015
4024
write ( "." ) ;
4016
- emitNodeWithoutSourceMap ( memberName ) ;
4025
+ emitNodeWithCommentsAndWithoutSourcemap ( memberName ) ;
4017
4026
}
4018
4027
}
4019
4028
@@ -4081,10 +4090,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
4081
4090
emitMemberAccessForPropertyName ( ( < MethodDeclaration > member ) . name ) ;
4082
4091
emitEnd ( ( < MethodDeclaration > member ) . name ) ;
4083
4092
write ( " = " ) ;
4084
- emitStart ( member ) ;
4085
4093
emitFunctionDeclaration ( < MethodDeclaration > member ) ;
4086
4094
emitEnd ( member ) ;
4087
- emitEnd ( member ) ;
4088
4095
write ( ";" ) ;
4089
4096
emitTrailingComments ( member ) ;
4090
4097
}
@@ -5501,11 +5508,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
5501
5508
emitStart ( specifier ) ;
5502
5509
emitContainingModuleName ( specifier ) ;
5503
5510
write ( "." ) ;
5504
- emitNodeWithoutSourceMap ( specifier . name ) ;
5511
+ emitNodeWithCommentsAndWithoutSourcemap ( specifier . name ) ;
5505
5512
write ( " = " ) ;
5506
5513
write ( generatedName ) ;
5507
5514
write ( "." ) ;
5508
- emitNodeWithoutSourceMap ( specifier . propertyName || specifier . name ) ;
5515
+ emitNodeWithCommentsAndWithoutSourcemap ( specifier . propertyName || specifier . name ) ;
5509
5516
write ( ";" ) ;
5510
5517
emitEnd ( specifier ) ;
5511
5518
}
@@ -5528,7 +5535,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
5528
5535
}
5529
5536
else {
5530
5537
if ( ! node . exportClause || resolver . isValueAliasDeclaration ( node ) ) {
5531
- emitStart ( node ) ;
5532
5538
write ( "export " ) ;
5533
5539
if ( node . exportClause ) {
5534
5540
// export { x, y, ... }
@@ -5541,10 +5547,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
5541
5547
}
5542
5548
if ( node . moduleSpecifier ) {
5543
5549
write ( " from " ) ;
5544
- emitNodeWithoutSourceMap ( node . moduleSpecifier ) ;
5550
+ emit ( node . moduleSpecifier ) ;
5545
5551
}
5546
5552
write ( ";" ) ;
5547
- emitEnd ( node ) ;
5548
5553
}
5549
5554
}
5550
5555
}
@@ -5558,13 +5563,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
5558
5563
if ( needsComma ) {
5559
5564
write ( ", " ) ;
5560
5565
}
5561
- emitStart ( specifier ) ;
5562
5566
if ( specifier . propertyName ) {
5563
- emitNodeWithoutSourceMap ( specifier . propertyName ) ;
5567
+ emit ( specifier . propertyName ) ;
5564
5568
write ( " as " ) ;
5565
5569
}
5566
- emitNodeWithoutSourceMap ( specifier . name ) ;
5567
- emitEnd ( specifier ) ;
5570
+ emit ( specifier . name ) ;
5568
5571
needsComma = true ;
5569
5572
}
5570
5573
}
@@ -5851,7 +5854,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
5851
5854
writeLine ( ) ;
5852
5855
write ( "'" ) ;
5853
5856
if ( node . kind === SyntaxKind . Identifier ) {
5854
- emitNodeWithoutSourceMap ( node ) ;
5857
+ emitNodeWithCommentsAndWithoutSourcemap ( node ) ;
5855
5858
}
5856
5859
else {
5857
5860
emitDeclarationName ( < Declaration > node ) ;
@@ -6178,9 +6181,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
6178
6181
writeLine ( ) ;
6179
6182
for ( let e of ( < ExportDeclaration > importNode ) . exportClause . elements ) {
6180
6183
write ( `${ reexportsVariableName } ["` ) ;
6181
- emitNodeWithoutSourceMap ( e . name ) ;
6184
+ emitNodeWithCommentsAndWithoutSourcemap ( e . name ) ;
6182
6185
write ( `"] = ${ parameterName } ["` ) ;
6183
- emitNodeWithoutSourceMap ( e . propertyName || e . name ) ;
6186
+ emitNodeWithCommentsAndWithoutSourcemap ( e . propertyName || e . name ) ;
6184
6187
write ( `"];` ) ;
6185
6188
writeLine ( ) ;
6186
6189
}
@@ -6594,28 +6597,41 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
6594
6597
emitLeadingComments ( node . endOfFileToken ) ;
6595
6598
}
6596
6599
6597
- function emitNodeWithoutSourceMap ( node : Node ) : void {
6598
- if ( ! node ) {
6599
- return ;
6600
- }
6600
+ function emitNodeWithCommentsAndWithoutSourcemap ( node : Node ) : void {
6601
+ emitNodeConsideringCommentsOption ( node , emitNodeWithoutSourceMap ) ;
6602
+ }
6601
6603
6602
- if ( node . flags & NodeFlags . Ambient ) {
6603
- return emitOnlyPinnedOrTripleSlashComments ( node ) ;
6604
- }
6604
+ function emitNodeConsideringCommentsOption ( node : Node , emitNodeConsideringSourcemap : ( node : Node ) => void ) : void {
6605
+ if ( node ) {
6606
+ if ( node . flags & NodeFlags . Ambient ) {
6607
+ return emitOnlyPinnedOrTripleSlashComments ( node ) ;
6608
+ }
6605
6609
6606
- let emitComments = shouldEmitLeadingAndTrailingComments ( node ) ;
6607
- if ( emitComments ) {
6608
- emitLeadingComments ( node ) ;
6609
- }
6610
+ if ( isSpecializedCommentHandling ( node ) ) {
6611
+ // This is the node that will handle its own comments and sourcemap
6612
+ return emitNodeWithoutSourceMap ( node ) ;
6613
+ }
6614
+
6615
+ let emitComments = shouldEmitLeadingAndTrailingComments ( node ) ;
6616
+ if ( emitComments ) {
6617
+ emitLeadingComments ( node ) ;
6618
+ }
6610
6619
6611
- emitJavaScriptWorker ( node ) ;
6620
+ emitNodeConsideringSourcemap ( node ) ;
6612
6621
6613
- if ( emitComments ) {
6614
- emitTrailingComments ( node ) ;
6622
+ if ( emitComments ) {
6623
+ emitTrailingComments ( node ) ;
6624
+ }
6615
6625
}
6616
6626
}
6617
6627
6618
- function shouldEmitLeadingAndTrailingComments ( node : Node ) {
6628
+ function emitNodeWithoutSourceMap ( node : Node ) : void {
6629
+ if ( node ) {
6630
+ emitJavaScriptWorker ( node ) ;
6631
+ }
6632
+ }
6633
+
6634
+ function isSpecializedCommentHandling ( node : Node ) : boolean {
6619
6635
switch ( node . kind ) {
6620
6636
// All of these entities are emitted in a specialized fashion. As such, we allow
6621
6637
// the specialized methods for each to handle the comments on the nodes.
@@ -6625,8 +6641,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
6625
6641
case SyntaxKind . ImportEqualsDeclaration :
6626
6642
case SyntaxKind . TypeAliasDeclaration :
6627
6643
case SyntaxKind . ExportAssignment :
6628
- return false ;
6644
+ return true ;
6645
+ }
6646
+ }
6629
6647
6648
+ function shouldEmitLeadingAndTrailingComments ( node : Node ) {
6649
+ switch ( node . kind ) {
6630
6650
case SyntaxKind . VariableStatement :
6631
6651
return shouldEmitLeadingAndTrailingCommentsForVariableStatement ( < VariableStatement > node ) ;
6632
6652
@@ -6641,6 +6661,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
6641
6661
return shouldEmitEnumDeclaration ( < EnumDeclaration > node ) ;
6642
6662
}
6643
6663
6664
+ // If the node is emitted in specialized fashion, dont emit comments as this node will handle
6665
+ // emitting comments when emitting itself
6666
+ Debug . assert ( ! isSpecializedCommentHandling ( node ) ) ;
6667
+
6644
6668
// If this is the expression body of an arrow function that we're down-leveling,
6645
6669
// then we don't want to emit comments when we emit the body. It will have already
6646
6670
// been taken care of when we emitted the 'return' statement for the function
0 commit comments