@@ -700,23 +700,46 @@ module ts {
700
700
}
701
701
}
702
702
703
- function emitCommaList ( nodes : Node [ ] , count ?: number ) {
704
- if ( ! ( count >= 0 ) ) count = nodes . length ;
703
+ function emitTrailingCommaIfPresent ( nodeList : NodeArray < Node > , isMultiline : boolean ) : void {
704
+ if ( nodeList . hasTrailingComma ) {
705
+ write ( "," ) ;
706
+ if ( isMultiline ) {
707
+ writeLine ( ) ;
708
+ }
709
+ }
710
+ }
711
+
712
+ function emitCommaList ( nodes : NodeArray < Node > , includeTrailingComma : boolean , count ?: number ) {
713
+ if ( ! ( count >= 0 ) ) {
714
+ count = nodes . length ;
715
+ }
705
716
if ( nodes ) {
706
717
for ( var i = 0 ; i < count ; i ++ ) {
707
- if ( i ) write ( ", " ) ;
718
+ if ( i ) {
719
+ write ( ", " ) ;
720
+ }
708
721
emit ( nodes [ i ] ) ;
709
722
}
723
+
724
+ if ( includeTrailingComma ) {
725
+ emitTrailingCommaIfPresent ( nodes , /*isMultiline*/ false ) ;
726
+ }
710
727
}
711
728
}
712
729
713
- function emitMultiLineList ( nodes : Node [ ] ) {
730
+ function emitMultiLineList ( nodes : NodeArray < Node > , includeTrailingComma : boolean ) {
714
731
if ( nodes ) {
715
732
for ( var i = 0 ; i < nodes . length ; i ++ ) {
716
- if ( i ) write ( "," ) ;
733
+ if ( i ) {
734
+ write ( "," ) ;
735
+ }
717
736
writeLine ( ) ;
718
737
emit ( nodes [ i ] ) ;
719
738
}
739
+
740
+ if ( includeTrailingComma ) {
741
+ emitTrailingCommaIfPresent ( nodes , /*isMultiline*/ true ) ;
742
+ }
720
743
}
721
744
}
722
745
@@ -824,29 +847,18 @@ module ts {
824
847
}
825
848
}
826
849
827
- function emitTrailingCommaIfPresent ( nodeList : NodeArray < Node > , isMultiline : boolean ) : void {
828
- if ( nodeList . hasTrailingComma ) {
829
- write ( "," ) ;
830
- if ( isMultiline ) {
831
- writeLine ( ) ;
832
- }
833
- }
834
- }
835
-
836
850
function emitArrayLiteral ( node : ArrayLiteral ) {
837
851
if ( node . flags & NodeFlags . MultiLine ) {
838
852
write ( "[" ) ;
839
853
increaseIndent ( ) ;
840
- emitMultiLineList ( node . elements ) ;
841
- emitTrailingCommaIfPresent ( node . elements , /*isMultiline*/ true ) ;
854
+ emitMultiLineList ( node . elements , /*includeTrailingComma*/ true ) ;
842
855
decreaseIndent ( ) ;
843
856
writeLine ( ) ;
844
857
write ( "]" ) ;
845
858
}
846
859
else {
847
860
write ( "[" ) ;
848
- emitCommaList ( node . elements ) ;
849
- emitTrailingCommaIfPresent ( node . elements , /*isMultiline*/ false ) ;
861
+ emitCommaList ( node . elements , /*includeTrailingComma*/ true ) ;
850
862
write ( "]" ) ;
851
863
}
852
864
}
@@ -858,24 +870,14 @@ module ts {
858
870
else if ( node . flags & NodeFlags . MultiLine ) {
859
871
write ( "{" ) ;
860
872
increaseIndent ( ) ;
861
- emitMultiLineList ( node . properties ) ;
862
-
863
- if ( compilerOptions . target === ScriptTarget . ES5 ) {
864
- emitTrailingCommaIfPresent ( node . properties , /*isMultiline*/ true ) ;
865
- }
866
-
873
+ emitMultiLineList ( node . properties , /*includeTrailingComma*/ compilerOptions . target >= ScriptTarget . ES5 ) ;
867
874
decreaseIndent ( ) ;
868
875
writeLine ( ) ;
869
876
write ( "}" ) ;
870
877
}
871
878
else {
872
879
write ( "{ " ) ;
873
- emitCommaList ( node . properties ) ;
874
-
875
- if ( compilerOptions . target === ScriptTarget . ES5 ) {
876
- emitTrailingCommaIfPresent ( node . properties , /*isMultiline*/ false ) ;
877
- }
878
-
880
+ emitCommaList ( node . properties , /*includeTrailingComma*/ compilerOptions . target >= ScriptTarget . ES5 ) ;
879
881
write ( " }" ) ;
880
882
}
881
883
}
@@ -921,13 +923,13 @@ module ts {
921
923
emitThis ( node . func ) ;
922
924
if ( node . arguments . length ) {
923
925
write ( ", " ) ;
924
- emitCommaList ( node . arguments ) ;
926
+ emitCommaList ( node . arguments , /*includeTrailingComma*/ false ) ;
925
927
}
926
928
write ( ")" ) ;
927
929
}
928
930
else {
929
931
write ( "(" ) ;
930
- emitCommaList ( node . arguments ) ;
932
+ emitCommaList ( node . arguments , /*includeTrailingComma*/ false ) ;
931
933
write ( ")" ) ;
932
934
}
933
935
}
@@ -937,7 +939,7 @@ module ts {
937
939
emit ( node . func ) ;
938
940
if ( node . arguments ) {
939
941
write ( "(" ) ;
940
- emitCommaList ( node . arguments ) ;
942
+ emitCommaList ( node . arguments , /*includeTrailingComma*/ false ) ;
941
943
write ( ")" ) ;
942
944
}
943
945
}
@@ -1110,7 +1112,7 @@ module ts {
1110
1112
if ( node . declarations ) {
1111
1113
emitToken ( SyntaxKind . VarKeyword , endPos ) ;
1112
1114
write ( " " ) ;
1113
- emitCommaList ( node . declarations ) ;
1115
+ emitCommaList ( node . declarations , /*includeTrailingComma*/ false ) ;
1114
1116
}
1115
1117
if ( node . initializer ) {
1116
1118
emit ( node . initializer ) ;
@@ -1258,7 +1260,7 @@ module ts {
1258
1260
function emitVariableStatement ( node : VariableStatement ) {
1259
1261
emitLeadingComments ( node ) ;
1260
1262
if ( ! ( node . flags & NodeFlags . Export ) ) write ( "var " ) ;
1261
- emitCommaList ( node . declarations ) ;
1263
+ emitCommaList ( node . declarations , /*includeTrailingComma*/ false ) ;
1262
1264
write ( ";" ) ;
1263
1265
emitTrailingComments ( node ) ;
1264
1266
}
@@ -1367,7 +1369,7 @@ module ts {
1367
1369
increaseIndent ( ) ;
1368
1370
write ( "(" ) ;
1369
1371
if ( node ) {
1370
- emitCommaList ( node . parameters , node . parameters . length - ( hasRestParameters ( node ) ? 1 : 0 ) ) ;
1372
+ emitCommaList ( node . parameters , /*includeTrailingComma*/ false , node . parameters . length - ( hasRestParameters ( node ) ? 1 : 0 ) ) ;
1371
1373
}
1372
1374
write ( ")" ) ;
1373
1375
decreaseIndent ( ) ;
0 commit comments