@@ -153,7 +153,7 @@ namespace ts {
153
153
for ( let i = 0 ; i < numNodes ; i ++ ) {
154
154
const currentNode = bundle ? bundle . sourceFiles [ i ] : node ;
155
155
const sourceFile = isSourceFile ( currentNode ) ? currentNode : currentSourceFile ;
156
- const shouldSkip = compilerOptions . noEmitHelpers || ( sourceFile && getExternalHelpersModuleName ( sourceFile ) !== undefined ) ;
156
+ const shouldSkip = compilerOptions . noEmitHelpers || getExternalHelpersModuleName ( sourceFile ) !== undefined ;
157
157
const shouldBundle = isSourceFile ( currentNode ) && ! isOwnFileEmit ;
158
158
const helpers = getEmitHelpers ( currentNode ) ;
159
159
if ( helpers ) {
@@ -212,7 +212,7 @@ namespace ts {
212
212
emitLeadingCommentsOfPosition,
213
213
} = comments ;
214
214
215
- let currentSourceFile : SourceFile ;
215
+ let currentSourceFile : SourceFile | undefined ;
216
216
let nodeIdToGeneratedName : string [ ] ; // Map of generated names for specific nodes.
217
217
let autoGeneratedIdToGeneratedName : string [ ] ; // Map of generated names for temp and loop variables.
218
218
let generatedNames : Map < string > ; // Set of names generated by the NameGenerator.
@@ -264,7 +264,12 @@ namespace ts {
264
264
return endPrint ( ) ;
265
265
}
266
266
267
- function writeNode ( hint : EmitHint , node : Node , sourceFile : SourceFile , output : EmitTextWriter ) {
267
+ /**
268
+ * If `sourceFile` is `undefined`, `node` must be a synthesized `TypeNode`.
269
+ */
270
+ function writeNode ( hint : EmitHint , node : TypeNode , sourceFile : undefined , output : EmitTextWriter ) : void ;
271
+ function writeNode ( hint : EmitHint , node : Node , sourceFile : SourceFile , output : EmitTextWriter ) : void ;
272
+ function writeNode ( hint : EmitHint , node : Node , sourceFile : SourceFile | undefined , output : EmitTextWriter ) {
268
273
const previousWriter = writer ;
269
274
setWriter ( output ) ;
270
275
print ( hint , node , sourceFile ) ;
@@ -305,8 +310,10 @@ namespace ts {
305
310
return text ;
306
311
}
307
312
308
- function print ( hint : EmitHint , node : Node , sourceFile : SourceFile ) {
309
- setSourceFile ( sourceFile ) ;
313
+ function print ( hint : EmitHint , node : Node , sourceFile : SourceFile | undefined ) {
314
+ if ( sourceFile ) {
315
+ setSourceFile ( sourceFile ) ;
316
+ }
310
317
pipelineEmitWithNotification ( hint , node ) ;
311
318
}
312
319
@@ -733,6 +740,9 @@ namespace ts {
733
740
// Transformation nodes
734
741
case SyntaxKind . PartiallyEmittedExpression :
735
742
return emitPartiallyEmittedExpression ( < PartiallyEmittedExpression > node ) ;
743
+
744
+ case SyntaxKind . CommaListExpression :
745
+ return emitCommaList ( < CommaListExpression > node ) ;
736
746
}
737
747
}
738
748
@@ -778,6 +788,7 @@ namespace ts {
778
788
779
789
function emitIdentifier ( node : Identifier ) {
780
790
write ( getTextOfNode ( node , /*includeTrivia*/ false ) ) ;
791
+ emitTypeArguments ( node , node . typeArguments ) ;
781
792
}
782
793
783
794
//
@@ -812,6 +823,7 @@ namespace ts {
812
823
function emitTypeParameter ( node : TypeParameterDeclaration ) {
813
824
emit ( node . name ) ;
814
825
emitWithPrefix ( " extends " , node . constraint ) ;
826
+ emitWithPrefix ( " = " , node . default ) ;
815
827
}
816
828
817
829
function emitParameter ( node : ParameterDeclaration ) {
@@ -952,7 +964,10 @@ namespace ts {
952
964
953
965
function emitTypeLiteral ( node : TypeLiteralNode ) {
954
966
write ( "{" ) ;
955
- emitList ( node , node . members , ListFormat . TypeLiteralMembers ) ;
967
+ // If the literal is empty, do not add spaces between braces.
968
+ if ( node . members . length > 0 ) {
969
+ emitList ( node , node . members , getEmitFlags ( node ) & EmitFlags . SingleLine ? ListFormat . SingleLineTypeLiteralMembers : ListFormat . MultiLineTypeLiteralMembers ) ;
970
+ }
956
971
write ( "}" ) ;
957
972
}
958
973
@@ -999,9 +1014,15 @@ namespace ts {
999
1014
}
1000
1015
1001
1016
function emitMappedType ( node : MappedTypeNode ) {
1017
+ const emitFlags = getEmitFlags ( node ) ;
1002
1018
write ( "{" ) ;
1003
- writeLine ( ) ;
1004
- increaseIndent ( ) ;
1019
+ if ( emitFlags & EmitFlags . SingleLine ) {
1020
+ write ( " " ) ;
1021
+ }
1022
+ else {
1023
+ writeLine ( ) ;
1024
+ increaseIndent ( ) ;
1025
+ }
1005
1026
writeIfPresent ( node . readonlyToken , "readonly " ) ;
1006
1027
write ( "[" ) ;
1007
1028
emit ( node . typeParameter . name ) ;
@@ -1012,8 +1033,13 @@ namespace ts {
1012
1033
write ( ": " ) ;
1013
1034
emit ( node . type ) ;
1014
1035
write ( ";" ) ;
1015
- writeLine ( ) ;
1016
- decreaseIndent ( ) ;
1036
+ if ( emitFlags & EmitFlags . SingleLine ) {
1037
+ write ( " " ) ;
1038
+ }
1039
+ else {
1040
+ writeLine ( ) ;
1041
+ decreaseIndent ( ) ;
1042
+ }
1017
1043
write ( "}" ) ;
1018
1044
}
1019
1045
@@ -1032,7 +1058,7 @@ namespace ts {
1032
1058
}
1033
1059
else {
1034
1060
write ( "{" ) ;
1035
- emitList ( node , elements , ListFormat . ObjectBindingPatternElements ) ;
1061
+ emitList ( node , elements , getEmitFlags ( node ) & EmitFlags . SingleLine ? ListFormat . ObjectBindingPatternElements : ListFormat . ObjectBindingPatternElementsWithSpaceBetweenBraces ) ;
1036
1062
write ( "}" ) ;
1037
1063
}
1038
1064
}
@@ -2101,6 +2127,10 @@ namespace ts {
2101
2127
emitExpression ( node . expression ) ;
2102
2128
}
2103
2129
2130
+ function emitCommaList ( node : CommaListExpression ) {
2131
+ emitExpressionList ( node , node . elements , ListFormat . CommaListElements ) ;
2132
+ }
2133
+
2104
2134
/**
2105
2135
* Emits any prologue directives at the start of a Statement list, returning the
2106
2136
* number of prologue directives written to the output.
@@ -2630,7 +2660,9 @@ namespace ts {
2630
2660
if ( node . kind === SyntaxKind . StringLiteral && ( < StringLiteral > node ) . textSourceNode ) {
2631
2661
const textSourceNode = ( < StringLiteral > node ) . textSourceNode ;
2632
2662
if ( isIdentifier ( textSourceNode ) ) {
2633
- return "\"" + escapeNonAsciiCharacters ( escapeString ( getTextOfNode ( textSourceNode ) ) ) + "\"" ;
2663
+ return getEmitFlags ( node ) & EmitFlags . NoAsciiEscaping ?
2664
+ `"${ escapeString ( getTextOfNode ( textSourceNode ) ) } "` :
2665
+ `"${ escapeNonAsciiString ( getTextOfNode ( textSourceNode ) ) } "` ;
2634
2666
}
2635
2667
else {
2636
2668
return getLiteralTextOfNode ( textSourceNode ) ;
@@ -2943,14 +2975,18 @@ namespace ts {
2943
2975
// Precomputed Formats
2944
2976
Modifiers = SingleLine | SpaceBetweenSiblings ,
2945
2977
HeritageClauses = SingleLine | SpaceBetweenSiblings ,
2946
- TypeLiteralMembers = MultiLine | Indented ,
2978
+ SingleLineTypeLiteralMembers = SingleLine | SpaceBetweenBraces | SpaceBetweenSiblings | Indented ,
2979
+ MultiLineTypeLiteralMembers = MultiLine | Indented ,
2980
+
2947
2981
TupleTypeElements = CommaDelimited | SpaceBetweenSiblings | SingleLine | Indented ,
2948
2982
UnionTypeConstituents = BarDelimited | SpaceBetweenSiblings | SingleLine ,
2949
2983
IntersectionTypeConstituents = AmpersandDelimited | SpaceBetweenSiblings | SingleLine ,
2950
- ObjectBindingPatternElements = SingleLine | AllowTrailingComma | SpaceBetweenBraces | CommaDelimited | SpaceBetweenSiblings ,
2984
+ ObjectBindingPatternElements = SingleLine | CommaDelimited | SpaceBetweenSiblings ,
2985
+ ObjectBindingPatternElementsWithSpaceBetweenBraces = SingleLine | AllowTrailingComma | SpaceBetweenBraces | CommaDelimited | SpaceBetweenSiblings ,
2951
2986
ArrayBindingPatternElements = SingleLine | AllowTrailingComma | CommaDelimited | SpaceBetweenSiblings ,
2952
2987
ObjectLiteralExpressionProperties = PreserveLines | CommaDelimited | SpaceBetweenSiblings | SpaceBetweenBraces | Indented | Braces ,
2953
2988
ArrayLiteralExpressionElements = PreserveLines | CommaDelimited | SpaceBetweenSiblings | AllowTrailingComma | Indented | SquareBrackets ,
2989
+ CommaListElements = CommaDelimited | SpaceBetweenSiblings | SingleLine ,
2954
2990
CallExpressionArguments = CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis ,
2955
2991
NewExpressionArguments = CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis | OptionalIfUndefined ,
2956
2992
TemplateExpressionSpans = SingleLine | NoInterveningComments ,
0 commit comments