@@ -851,7 +851,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
851
851
}
852
852
}
853
853
854
- function emitLinePreservingList ( parent : Node , nodes : NodeArray < Node > , allowTrailingComma : boolean , spacesBetweenBraces : boolean , commentsBeforePunctuation : boolean ) {
854
+ function emitLinePreservingList ( parent : Node , nodes : NodeArray < Node > , allowTrailingComma : boolean , spacesBetweenBraces : boolean ) {
855
855
Debug . assert ( nodes . length > 0 ) ;
856
856
857
857
increaseIndent ( ) ;
@@ -877,9 +877,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
877
877
}
878
878
879
879
emit ( nodes [ i ] ) ;
880
- if ( commentsBeforePunctuation ) {
881
- emitLeadingCommentsAtEnd ( nodes [ i ] ) ;
882
- }
883
880
}
884
881
885
882
if ( nodes . hasTrailingComma && allowTrailingComma ) {
@@ -898,7 +895,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
898
895
}
899
896
}
900
897
901
- function emitList < TNode extends Node > ( nodes : TNode [ ] , start : number , count : number , multiLine : boolean , trailingComma : boolean , leadingComma ?: boolean , noTrailingNewLine ?: boolean , commentsBeforePunctuation ?: boolean , emitNode ?: ( node : TNode ) => void ) : number {
898
+ function emitList < TNode extends Node > ( nodes : TNode [ ] , start : number , count : number , multiLine : boolean , trailingComma : boolean , leadingComma ?: boolean , noTrailingNewLine ?: boolean , emitNode ?: ( node : TNode ) => void ) : number {
902
899
if ( ! emitNode ) {
903
900
emitNode = emit ;
904
901
}
@@ -916,10 +913,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
916
913
}
917
914
}
918
915
const node = nodes [ start + i ] ;
916
+ // This emitting is to make sure we emit following comment properly
917
+ // ...(x, /*comment1*/ y)...
918
+ // ^ => node.pos
919
+ // "comment1" is not considered leading comment for "y" but rather
920
+ // considered as trailing comment of the previous node.
921
+ emitTrailingCommentsOfPosition ( node . pos ) ;
919
922
emitNode ( node ) ;
920
- if ( commentsBeforePunctuation ) {
921
- emitLeadingCommentsAtEnd ( nodes [ i ] ) ;
922
- }
923
923
leadingComma = true ;
924
924
}
925
925
if ( trailingComma ) {
@@ -1897,7 +1897,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1897
1897
}
1898
1898
else if ( languageVersion >= ScriptTarget . ES6 || ! forEach ( elements , isSpreadElementExpression ) ) {
1899
1899
write ( "[" ) ;
1900
- emitLinePreservingList ( node , node . elements , elements . hasTrailingComma , /*spacesBetweenBraces*/ false , /*commentsBeforePunctuation*/ true ) ;
1900
+ emitLinePreservingList ( node , node . elements , elements . hasTrailingComma , /*spacesBetweenBraces*/ false ) ;
1901
1901
write ( "]" ) ;
1902
1902
}
1903
1903
else {
@@ -1921,7 +1921,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1921
1921
// then try to preserve the original shape of the object literal.
1922
1922
// Otherwise just try to preserve the formatting.
1923
1923
if ( numElements === properties . length ) {
1924
- emitLinePreservingList ( node , properties , /*allowTrailingComma*/ languageVersion >= ScriptTarget . ES5 , /*spacesBetweenBraces*/ true , /*commentsBeforePunctuation*/ true ) ;
1924
+ emitLinePreservingList ( node , properties , /*allowTrailingComma*/ languageVersion >= ScriptTarget . ES5 , /*spacesBetweenBraces*/ true ) ;
1925
1925
}
1926
1926
else {
1927
1927
const multiLine = node . multiLine ;
@@ -2166,6 +2166,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2166
2166
function emitPropertyAssignment ( node : PropertyDeclaration ) {
2167
2167
emit ( node . name ) ;
2168
2168
write ( ": " ) ;
2169
+ // This is to ensure that we emit comment in the following case:
2170
+ // For example:
2171
+ // obj = {
2172
+ // id: /*comment1*/ ()=>void
2173
+ // }
2174
+ // "comment1" is not considered to be leading comment for node.initializer
2175
+ // but rather a trailing comment on the previous node.
2176
+ emitTrailingCommentsOfPosition ( node . initializer . pos ) ;
2169
2177
emit ( node . initializer ) ;
2170
2178
}
2171
2179
@@ -2277,7 +2285,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2277
2285
}
2278
2286
2279
2287
emit ( node . expression ) ;
2280
- emitLeadingCommentsAtEnd ( node . expression ) ;
2281
2288
const dotRangeStart = nodeIsSynthesized ( node . expression ) ? - 1 : node . expression . end ;
2282
2289
const dotRangeEnd = nodeIsSynthesized ( node . expression ) ? - 1 : skipTrivia ( currentText , node . expression . end ) + 1 ;
2283
2290
const dotToken = < TextRange > { pos : dotRangeStart , end : dotRangeEnd } ;
@@ -2494,17 +2501,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2494
2501
emitThis ( expression ) ;
2495
2502
if ( node . arguments . length ) {
2496
2503
write ( ", " ) ;
2497
- emitTrailingCommentsOfPosition ( node . arguments . pos ) ;
2498
2504
emitCommaList ( node . arguments ) ;
2499
- emitLeadingCommentsAtEnd ( node . arguments ) ;
2500
2505
}
2501
2506
write ( ")" ) ;
2502
2507
}
2503
2508
else {
2504
2509
write ( "(" ) ;
2505
- emitTrailingCommentsOfPosition ( node . arguments . pos ) ;
2506
2510
emitCommaList ( node . arguments ) ;
2507
- emitLeadingCommentsAtEnd ( node . arguments ) ;
2508
2511
write ( ")" ) ;
2509
2512
}
2510
2513
}
@@ -2605,7 +2608,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2605
2608
2606
2609
write ( "(" ) ;
2607
2610
emit ( node . expression ) ;
2608
- emitLeadingCommentsAtEnd ( node . expression ) ;
2609
2611
write ( ")" ) ;
2610
2612
}
2611
2613
@@ -2884,7 +2886,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
2884
2886
}
2885
2887
else {
2886
2888
emit ( node . left ) ;
2887
- emitLeadingCommentsAtEnd ( node . left ) ;
2888
2889
// Add indentation before emit the operator if the operator is on different line
2889
2890
// For example:
2890
2891
// 3
@@ -3897,7 +3898,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
3897
3898
}
3898
3899
emitNodeWithCommentsAndWithoutSourcemap ( node . name ) ;
3899
3900
emitEnd ( node . name ) ;
3900
- emitLeadingCommentsAtEnd ( node . name ) ;
3901
3901
}
3902
3902
3903
3903
function createVoidZero ( ) : Expression {
@@ -4040,7 +4040,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
4040
4040
emit ( name ) ;
4041
4041
}
4042
4042
4043
- emitLeadingCommentsAtEnd ( name ) ;
4044
4043
write ( " = " ) ;
4045
4044
emit ( value ) ;
4046
4045
} ) ;
@@ -4592,7 +4591,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
4592
4591
emitStart ( restParam ) ;
4593
4592
write ( "var " ) ;
4594
4593
emitNodeWithCommentsAndWithoutSourcemap ( restParam . name ) ;
4595
- emitLeadingCommentsAtEnd ( restParam . name ) ;
4596
4594
write ( " = [];" ) ;
4597
4595
emitEnd ( restParam ) ;
4598
4596
emitTrailingComments ( restParam ) ;
@@ -4614,7 +4612,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
4614
4612
writeLine ( ) ;
4615
4613
emitStart ( restParam ) ;
4616
4614
emitNodeWithCommentsAndWithoutSourcemap ( restParam . name ) ;
4617
- emitLeadingCommentsAtEnd ( restParam . name ) ;
4618
4615
write ( "[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];" ) ;
4619
4616
emitEnd ( restParam ) ;
4620
4617
decreaseIndent ( ) ;
@@ -4636,7 +4633,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
4636
4633
function emitDeclarationName ( node : Declaration ) {
4637
4634
if ( node . name ) {
4638
4635
emitNodeWithCommentsAndWithoutSourcemap ( node . name ) ;
4639
- emitLeadingCommentsAtEnd ( node . name ) ;
4640
4636
}
4641
4637
else {
4642
4638
write ( getGeneratedNameForNode ( node ) ) ;
@@ -4664,7 +4660,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
4664
4660
const { kind, parent } = node ;
4665
4661
if ( kind !== SyntaxKind . MethodDeclaration &&
4666
4662
kind !== SyntaxKind . MethodSignature &&
4667
- kind !== SyntaxKind . ArrowFunction &&
4668
4663
parent &&
4669
4664
parent . kind !== SyntaxKind . PropertyAssignment &&
4670
4665
parent . kind !== SyntaxKind . CallExpression &&
@@ -4739,11 +4734,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
4739
4734
const parameters = node . parameters ;
4740
4735
const skipCount = node . parameters . length && ( < Identifier > node . parameters [ 0 ] . name ) . originalKeywordKind === SyntaxKind . ThisKeyword ? 1 : 0 ;
4741
4736
const omitCount = languageVersion < ScriptTarget . ES6 && hasDeclaredRestParameter ( node ) ? 1 : 0 ;
4742
- emitTrailingCommentsOfPosition ( node . parameters . pos ) ;
4743
- emitList ( parameters , skipCount , parameters . length - omitCount - skipCount , /*multiLine*/ false , /*trailingComma*/ false , /*leadingComma*/ false , /*noTrailingNewLine*/ false , /*commentsBeforePunctuation*/ true ) ;
4744
- if ( ( parameters . length - omitCount - skipCount ) <= 0 ) {
4745
- emitLeadingCommentsAtEnd ( node . parameters ) ;
4746
- }
4737
+ emitList ( parameters , skipCount , parameters . length - omitCount - skipCount , /*multiLine*/ false , /*trailingComma*/ false ) ;
4747
4738
}
4748
4739
write ( ")" ) ;
4749
4740
decreaseIndent ( ) ;
@@ -5800,7 +5791,7 @@ const _super = (function (geti, seti) {
5800
5791
writeLine ( ) ;
5801
5792
5802
5793
const decoratorCount = decorators ? decorators . length : 0 ;
5803
- let argumentsWritten = emitList ( decorators , 0 , decoratorCount , /*multiLine*/ true , /*trailingComma*/ false , /*leadingComma*/ false , /*noTrailingNewLine*/ true , /*commentsBeforePunctuation*/ false ,
5794
+ let argumentsWritten = emitList ( decorators , 0 , decoratorCount , /*multiLine*/ true , /*trailingComma*/ false , /*leadingComma*/ false , /*noTrailingNewLine*/ true ,
5804
5795
decorator => emit ( decorator . expression ) ) ;
5805
5796
if ( firstParameterDecorator ) {
5806
5797
argumentsWritten += emitDecoratorsOfParameters ( constructor , /*leadingComma*/ argumentsWritten > 0 ) ;
@@ -5900,7 +5891,7 @@ const _super = (function (geti, seti) {
5900
5891
writeLine ( ) ;
5901
5892
5902
5893
const decoratorCount = decorators ? decorators . length : 0 ;
5903
- let argumentsWritten = emitList ( decorators , 0 , decoratorCount , /*multiLine*/ true , /*trailingComma*/ false , /*leadingComma*/ false , /*noTrailingNewLine*/ true , /*commentsBeforePunctuation*/ false ,
5894
+ let argumentsWritten = emitList ( decorators , 0 , decoratorCount , /*multiLine*/ true , /*trailingComma*/ false , /*leadingComma*/ false , /*noTrailingNewLine*/ true ,
5904
5895
decorator => emit ( decorator . expression ) ) ;
5905
5896
5906
5897
if ( firstParameterDecorator ) {
@@ -5942,7 +5933,7 @@ const _super = (function (geti, seti) {
5942
5933
for ( const parameter of node . parameters ) {
5943
5934
if ( nodeIsDecorated ( parameter ) ) {
5944
5935
const decorators = parameter . decorators ;
5945
- argumentsWritten += emitList ( decorators , 0 , decorators . length , /*multiLine*/ true , /*trailingComma*/ false , /*leadingComma*/ leadingComma , /*noTrailingNewLine*/ true , /*commentsBeforePunctuation*/ false , decorator => {
5936
+ argumentsWritten += emitList ( decorators , 0 , decorators . length , /*multiLine*/ true , /*trailingComma*/ false , /*leadingComma*/ leadingComma , /*noTrailingNewLine*/ true , decorator => {
5946
5937
write ( `__param(${ parameterIndex } , ` ) ;
5947
5938
emit ( decorator . expression ) ;
5948
5939
write ( ")" ) ;
@@ -6356,7 +6347,6 @@ const _super = (function (geti, seti) {
6356
6347
emitExpressionForPropertyName ( node . name ) ;
6357
6348
emitEnd ( node ) ;
6358
6349
write ( ";" ) ;
6359
- emitLeadingCommentsAtEnd ( node . name ) ;
6360
6350
}
6361
6351
6362
6352
function writeEnumMemberDeclarationValue ( member : EnumMember ) {
@@ -8319,11 +8309,8 @@ const _super = (function (geti, seti) {
8319
8309
8320
8310
/**
8321
8311
* Emit trailing comments at the position. The term trailing comment is used here to describe following comment:
8322
- * x, /*comment1* / // comment2
8323
- * ^ => pos; the function will emit "comment1" and "comment2" in the emitJS
8324
- * However,
8325
8312
* x /*comment1* /, y
8326
- * 'comment1' is actually a leading comment of ',' and needs to be emitted using emitLeadingCommentsAtEnd
8313
+ * ^ => pos; the function will emit "comment1"
8327
8314
*/
8328
8315
function emitTrailingCommentsOfPosition ( pos : number ) {
8329
8316
if ( compilerOptions . removeComments ) {
@@ -8336,18 +8323,7 @@ const _super = (function (geti, seti) {
8336
8323
emitComments ( currentText , currentLineMap , writer , trailingComments , /*trailingSeparator*/ true , newLine , writeComment ) ;
8337
8324
}
8338
8325
8339
- /**
8340
- * Emit leading comments for the token after the current token.
8341
- * This is only needed for punctuation tokens. For example, in
8342
- * x /*comment1* /, y
8343
- * 'comment1' is a leading comment of ',' but needs to be emitted
8344
- * from x because there is no token for ','.
8345
- */
8346
- function emitLeadingCommentsAtEnd ( node : Node | NodeArray < any > ) {
8347
- emitLeadingCommentsOfPositionWorker ( node . end , /*trailingSeparator*/ false ) ;
8348
- }
8349
-
8350
- function emitLeadingCommentsOfPositionWorker ( pos : number , trailingSeparator = true ) {
8326
+ function emitLeadingCommentsOfPositionWorker ( pos : number ) {
8351
8327
if ( compilerOptions . removeComments ) {
8352
8328
return ;
8353
8329
}
@@ -8365,7 +8341,7 @@ const _super = (function (geti, seti) {
8365
8341
emitNewLineBeforeLeadingComments ( currentLineMap , writer , { pos : pos , end : pos } , leadingComments ) ;
8366
8342
8367
8343
// Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
8368
- emitComments ( currentText , currentLineMap , writer , leadingComments , trailingSeparator , newLine , writeComment ) ;
8344
+ emitComments ( currentText , currentLineMap , writer , leadingComments , /* trailingSeparator*/ true , newLine , writeComment ) ;
8369
8345
}
8370
8346
8371
8347
function emitDetachedCommentsAndUpdateCommentsInfo ( node : TextRange ) {
0 commit comments