@@ -1600,16 +1600,16 @@ module ts {
1600
1600
var emitLeadingCommentsOfPosition = compilerOptions . removeComments ? ( pos : number ) => { } : emitLeadingCommentsOfLocalPosition ;
1601
1601
1602
1602
var detachedCommentsInfo : { nodePos : number ; detachedCommentEndPos : number } [ ] ;
1603
+
1603
1604
/** Emit detached comments of the node */
1604
1605
var emitDetachedComments = compilerOptions . removeComments ? ( node : TextRange ) => { } : emitDetachedCommentsAtPosition ;
1605
1606
1606
- /** Emits /// or pinned which is comment starting with /*! comments */
1607
- var emitPinnedOrTripleSlashComments = compilerOptions . removeComments ? ( node : Node ) => { } : emitPinnedOrTripleSlashCommentsOfNode ;
1608
-
1609
1607
var writeComment = writeCommentRange ;
1610
1608
1611
1609
/** Emit a node */
1612
- var emit = emitNode ;
1610
+ var emitNodeWithoutSourceMap = compilerOptions . removeComments ? emitNodeWithoutSourceMapWithoutComments : emitNodeWithoutSourceMapWithComments ;
1611
+ var emit = emitNodeWithoutSourceMap ;
1612
+ var emitWithoutComments = emitNodeWithoutSourceMapWithoutComments ;
1613
1613
1614
1614
/** Called just before starting emit of a node */
1615
1615
var emitStart = function ( node : Node ) { } ;
@@ -2061,22 +2061,31 @@ module ts {
2061
2061
sourceMapDir = getDirectoryPath ( normalizePath ( jsFilePath ) ) ;
2062
2062
}
2063
2063
2064
- function emitNodeWithMap ( node : Node ) {
2064
+ function emitNodeWithSourceMap ( node : Node ) {
2065
2065
if ( node ) {
2066
2066
if ( node . kind != SyntaxKind . SourceFile ) {
2067
2067
recordEmitNodeStartSpan ( node ) ;
2068
- emitNode ( node ) ;
2068
+ emitNodeWithoutSourceMap ( node ) ;
2069
2069
recordEmitNodeEndSpan ( node ) ;
2070
2070
}
2071
2071
else {
2072
2072
recordNewSourceFileStart ( < SourceFile > node ) ;
2073
- emitNode ( node ) ;
2073
+ emitNodeWithoutSourceMap ( node ) ;
2074
2074
}
2075
2075
}
2076
2076
}
2077
2077
2078
+ function emitNodeWithSourceMapWithoutComments ( node : Node ) {
2079
+ if ( node ) {
2080
+ recordEmitNodeStartSpan ( node ) ;
2081
+ emitNodeWithoutSourceMapWithoutComments ( node ) ;
2082
+ recordEmitNodeEndSpan ( node ) ;
2083
+ }
2084
+ }
2085
+
2078
2086
writeEmittedFiles = writeJavaScriptAndSourceMapFile ;
2079
- emit = emitNodeWithMap ;
2087
+ emit = emitNodeWithSourceMap ;
2088
+ emitWithoutComments = emitNodeWithSourceMapWithoutComments ;
2080
2089
emitStart = recordEmitNodeStartSpan ;
2081
2090
emitEnd = recordEmitNodeEndSpan ;
2082
2091
emitToken = writeTextWithSpanRecord ;
@@ -3036,7 +3045,7 @@ module ts {
3036
3045
// Returns 'true' if the code was actually indented, false otherwise.
3037
3046
// If the code is not indented, an optional valueToWriteWhenNotIndenting will be
3038
3047
// emitted instead.
3039
- function indentIfOnDifferentLines ( parent : Node , node1 : Node , node2 : Node , valueToWriteWhenNotIndenting ?: string ) {
3048
+ function indentIfOnDifferentLines ( parent : Node , node1 : Node , node2 : Node , valueToWriteWhenNotIndenting ?: string ) : boolean {
3040
3049
var realNodesAreOnDifferentLines = preserveNewLines && ! nodeIsSynthesized ( parent ) && ! nodeEndIsOnSameLineAsNodeStart ( node1 , node2 ) ;
3041
3050
3042
3051
// Always use a newline for synthesized code if the synthesizer desires it.
@@ -3631,7 +3640,7 @@ module ts {
3631
3640
emitContainingModuleName ( node ) ;
3632
3641
write ( "." ) ;
3633
3642
}
3634
- emitNode ( node . name ) ;
3643
+ emitNodeWithoutSourceMap ( node . name ) ;
3635
3644
emitEnd ( node . name ) ;
3636
3645
}
3637
3646
@@ -3650,10 +3659,10 @@ module ts {
3650
3659
emitStart ( specifier . name ) ;
3651
3660
emitContainingModuleName ( specifier ) ;
3652
3661
write ( "." ) ;
3653
- emitNode ( specifier . name ) ;
3662
+ emitNodeWithoutSourceMap ( specifier . name ) ;
3654
3663
emitEnd ( specifier . name ) ;
3655
3664
write ( " = " ) ;
3656
- emitNode ( name ) ;
3665
+ emitNodeWithoutSourceMap ( name ) ;
3657
3666
write ( ";" ) ;
3658
3667
} ) ;
3659
3668
}
@@ -4046,14 +4055,14 @@ module ts {
4046
4055
writeLine ( ) ;
4047
4056
emitStart ( p ) ;
4048
4057
write ( "if (" ) ;
4049
- emitNode ( p . name ) ;
4058
+ emitNodeWithoutSourceMap ( p . name ) ;
4050
4059
write ( " === void 0)" ) ;
4051
4060
emitEnd ( p ) ;
4052
4061
write ( " { " ) ;
4053
4062
emitStart ( p ) ;
4054
- emitNode ( p . name ) ;
4063
+ emitNodeWithoutSourceMap ( p . name ) ;
4055
4064
write ( " = " ) ;
4056
- emitNode ( p . initializer ) ;
4065
+ emitNodeWithoutSourceMap ( p . initializer ) ;
4057
4066
emitEnd ( p ) ;
4058
4067
write ( "; }" ) ;
4059
4068
}
@@ -4070,7 +4079,7 @@ module ts {
4070
4079
emitLeadingComments ( restParam ) ;
4071
4080
emitStart ( restParam ) ;
4072
4081
write ( "var " ) ;
4073
- emitNode ( restParam . name ) ;
4082
+ emitNodeWithoutSourceMap ( restParam . name ) ;
4074
4083
write ( " = [];" ) ;
4075
4084
emitEnd ( restParam ) ;
4076
4085
emitTrailingComments ( restParam ) ;
@@ -4091,7 +4100,7 @@ module ts {
4091
4100
increaseIndent ( ) ;
4092
4101
writeLine ( ) ;
4093
4102
emitStart ( restParam ) ;
4094
- emitNode ( restParam . name ) ;
4103
+ emitNodeWithoutSourceMap ( restParam . name ) ;
4095
4104
write ( "[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];" ) ;
4096
4105
emitEnd ( restParam ) ;
4097
4106
decreaseIndent ( ) ;
@@ -4112,7 +4121,7 @@ module ts {
4112
4121
4113
4122
function emitDeclarationName ( node : Declaration ) {
4114
4123
if ( node . name ) {
4115
- emitNode ( node . name ) ;
4124
+ emitNodeWithoutSourceMap ( node . name ) ;
4116
4125
}
4117
4126
else {
4118
4127
write ( resolver . getGeneratedNameForNode ( node ) ) ;
@@ -4273,7 +4282,7 @@ module ts {
4273
4282
4274
4283
// Don't emit comments on this body. We'll have already taken care of it above
4275
4284
// when we called emitDetachedComments.
4276
- emitNode ( body , /*disableComments:*/ true ) ;
4285
+ emitWithoutComments ( body ) ;
4277
4286
emitEnd ( body ) ;
4278
4287
write ( ";" ) ;
4279
4288
emitTempDeclarations ( /*newLine*/ false ) ;
@@ -4284,7 +4293,10 @@ module ts {
4284
4293
writeLine ( ) ;
4285
4294
emitLeadingComments ( node . body ) ;
4286
4295
write ( "return " ) ;
4287
- emit ( node . body , /*disableComments:*/ true ) ;
4296
+
4297
+ // Don't emit comments on this body. We'll have already taken care of it above
4298
+ // when we called emitDetachedComments.
4299
+ emitWithoutComments ( node . body ) ;
4288
4300
write ( ";" ) ;
4289
4301
emitTrailingComments ( node . body ) ;
4290
4302
@@ -4362,7 +4374,7 @@ module ts {
4362
4374
emitStart ( param ) ;
4363
4375
emitStart ( param . name ) ;
4364
4376
write ( "this." ) ;
4365
- emitNode ( param . name ) ;
4377
+ emitNodeWithoutSourceMap ( param . name ) ;
4366
4378
emitEnd ( param . name ) ;
4367
4379
write ( " = " ) ;
4368
4380
emit ( param . name ) ;
@@ -4376,15 +4388,15 @@ module ts {
4376
4388
// TODO: (jfreeman,drosen): comment on why this is emitNode instead of emit here.
4377
4389
if ( memberName . kind === SyntaxKind . StringLiteral || memberName . kind === SyntaxKind . NumericLiteral ) {
4378
4390
write ( "[" ) ;
4379
- emitNode ( memberName ) ;
4391
+ emitNodeWithoutSourceMap ( memberName ) ;
4380
4392
write ( "]" ) ;
4381
4393
}
4382
4394
else if ( memberName . kind === SyntaxKind . ComputedPropertyName ) {
4383
4395
emitComputedPropertyName ( < ComputedPropertyName > memberName ) ;
4384
4396
}
4385
4397
else {
4386
4398
write ( "." ) ;
4387
- emitNode ( memberName ) ;
4399
+ emitNodeWithoutSourceMap ( memberName ) ;
4388
4400
}
4389
4401
}
4390
4402
@@ -4877,11 +4889,11 @@ module ts {
4877
4889
emitStart ( specifier ) ;
4878
4890
emitContainingModuleName ( specifier ) ;
4879
4891
write ( "." ) ;
4880
- emitNode ( specifier . name ) ;
4892
+ emitNodeWithoutSourceMap ( specifier . name ) ;
4881
4893
write ( " = " ) ;
4882
4894
write ( generatedName ) ;
4883
4895
write ( "." ) ;
4884
- emitNode ( specifier . propertyName || specifier . name ) ;
4896
+ emitNodeWithoutSourceMap ( specifier . propertyName || specifier . name ) ;
4885
4897
write ( ";" ) ;
4886
4898
emitEnd ( specifier ) ;
4887
4899
} ) ;
@@ -5146,7 +5158,7 @@ module ts {
5146
5158
emitLeadingComments ( node . endOfFileToken ) ;
5147
5159
}
5148
5160
5149
- function emitNode ( node : Node , disableComments ?: boolean ) : void {
5161
+ function emitNodeWithoutSourceMapWithComments ( node : Node ) : void {
5150
5162
if ( ! node ) {
5151
5163
return ;
5152
5164
}
@@ -5155,7 +5167,7 @@ module ts {
5155
5167
return emitPinnedOrTripleSlashComments ( node ) ;
5156
5168
}
5157
5169
5158
- var emitComments = ! disableComments && shouldEmitLeadingAndTrailingComments ( node ) ;
5170
+ var emitComments = shouldEmitLeadingAndTrailingComments ( node ) ;
5159
5171
if ( emitComments ) {
5160
5172
emitLeadingComments ( node ) ;
5161
5173
}
@@ -5167,6 +5179,18 @@ module ts {
5167
5179
}
5168
5180
}
5169
5181
5182
+ function emitNodeWithoutSourceMapWithoutComments ( node : Node ) : void {
5183
+ if ( ! node ) {
5184
+ return ;
5185
+ }
5186
+
5187
+ if ( node . flags & NodeFlags . Ambient ) {
5188
+ return emitPinnedOrTripleSlashComments ( node ) ;
5189
+ }
5190
+
5191
+ emitJavaScriptWorker ( node ) ;
5192
+ }
5193
+
5170
5194
function shouldEmitLeadingAndTrailingComments ( node : Node ) {
5171
5195
switch ( node . kind ) {
5172
5196
// All of these entities are emitted in a specialized fashion. As such, we allow
@@ -5461,7 +5485,8 @@ module ts {
5461
5485
}
5462
5486
}
5463
5487
5464
- function emitPinnedOrTripleSlashCommentsOfNode ( node : Node ) {
5488
+ /** Emits /// or pinned which is comment starting with /*! comments */
5489
+ function emitPinnedOrTripleSlashComments ( node : Node ) {
5465
5490
var pinnedComments = ts . filter ( getLeadingCommentsToEmit ( node ) , isPinnedOrTripleSlashComment ) ;
5466
5491
5467
5492
function isPinnedOrTripleSlashComment ( comment : CommentRange ) {
0 commit comments