@@ -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
@@ -781,6 +788,7 @@ namespace ts {
781
788
782
789
function emitIdentifier ( node : Identifier ) {
783
790
write ( getTextOfNode ( node , /*includeTrivia*/ false ) ) ;
791
+ emitTypeArguments ( node , node . typeArguments ) ;
784
792
}
785
793
786
794
//
@@ -815,6 +823,7 @@ namespace ts {
815
823
function emitTypeParameter ( node : TypeParameterDeclaration ) {
816
824
emit ( node . name ) ;
817
825
emitWithPrefix ( " extends " , node . constraint ) ;
826
+ emitWithPrefix ( " = " , node . default ) ;
818
827
}
819
828
820
829
function emitParameter ( node : ParameterDeclaration ) {
@@ -955,7 +964,10 @@ namespace ts {
955
964
956
965
function emitTypeLiteral ( node : TypeLiteralNode ) {
957
966
write ( "{" ) ;
958
- 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
+ }
959
971
write ( "}" ) ;
960
972
}
961
973
@@ -1002,9 +1014,15 @@ namespace ts {
1002
1014
}
1003
1015
1004
1016
function emitMappedType ( node : MappedTypeNode ) {
1017
+ const emitFlags = getEmitFlags ( node ) ;
1005
1018
write ( "{" ) ;
1006
- writeLine ( ) ;
1007
- increaseIndent ( ) ;
1019
+ if ( emitFlags & EmitFlags . SingleLine ) {
1020
+ write ( " " ) ;
1021
+ }
1022
+ else {
1023
+ writeLine ( ) ;
1024
+ increaseIndent ( ) ;
1025
+ }
1008
1026
writeIfPresent ( node . readonlyToken , "readonly " ) ;
1009
1027
write ( "[" ) ;
1010
1028
emit ( node . typeParameter . name ) ;
@@ -1015,8 +1033,13 @@ namespace ts {
1015
1033
write ( ": " ) ;
1016
1034
emit ( node . type ) ;
1017
1035
write ( ";" ) ;
1018
- writeLine ( ) ;
1019
- decreaseIndent ( ) ;
1036
+ if ( emitFlags & EmitFlags . SingleLine ) {
1037
+ write ( " " ) ;
1038
+ }
1039
+ else {
1040
+ writeLine ( ) ;
1041
+ decreaseIndent ( ) ;
1042
+ }
1020
1043
write ( "}" ) ;
1021
1044
}
1022
1045
@@ -1035,7 +1058,7 @@ namespace ts {
1035
1058
}
1036
1059
else {
1037
1060
write ( "{" ) ;
1038
- emitList ( node , elements , ListFormat . ObjectBindingPatternElements ) ;
1061
+ emitList ( node , elements , getEmitFlags ( node ) & EmitFlags . SingleLine ? ListFormat . ObjectBindingPatternElements : ListFormat . ObjectBindingPatternElementsWithSpaceBetweenBraces ) ;
1039
1062
write ( "}" ) ;
1040
1063
}
1041
1064
}
@@ -1131,7 +1154,7 @@ namespace ts {
1131
1154
// check if constant enum value is integer
1132
1155
const constantValue = getConstantValue ( expression ) ;
1133
1156
// isFinite handles cases when constantValue is undefined
1134
- return isFinite ( constantValue )
1157
+ return typeof constantValue === "number" && isFinite ( constantValue )
1135
1158
&& Math . floor ( constantValue ) === constantValue
1136
1159
&& printerOptions . removeComments ;
1137
1160
}
@@ -2637,7 +2660,9 @@ namespace ts {
2637
2660
if ( node . kind === SyntaxKind . StringLiteral && ( < StringLiteral > node ) . textSourceNode ) {
2638
2661
const textSourceNode = ( < StringLiteral > node ) . textSourceNode ;
2639
2662
if ( isIdentifier ( textSourceNode ) ) {
2640
- return "\"" + escapeNonAsciiCharacters ( escapeString ( getTextOfNode ( textSourceNode ) ) ) + "\"" ;
2663
+ return getEmitFlags ( node ) & EmitFlags . NoAsciiEscaping ?
2664
+ `"${ escapeString ( getTextOfNode ( textSourceNode ) ) } "` :
2665
+ `"${ escapeNonAsciiString ( getTextOfNode ( textSourceNode ) ) } "` ;
2641
2666
}
2642
2667
else {
2643
2668
return getLiteralTextOfNode ( textSourceNode ) ;
@@ -2950,11 +2975,14 @@ namespace ts {
2950
2975
// Precomputed Formats
2951
2976
Modifiers = SingleLine | SpaceBetweenSiblings ,
2952
2977
HeritageClauses = SingleLine | SpaceBetweenSiblings ,
2953
- TypeLiteralMembers = MultiLine | Indented ,
2978
+ SingleLineTypeLiteralMembers = SingleLine | SpaceBetweenBraces | SpaceBetweenSiblings | Indented ,
2979
+ MultiLineTypeLiteralMembers = MultiLine | Indented ,
2980
+
2954
2981
TupleTypeElements = CommaDelimited | SpaceBetweenSiblings | SingleLine | Indented ,
2955
2982
UnionTypeConstituents = BarDelimited | SpaceBetweenSiblings | SingleLine ,
2956
2983
IntersectionTypeConstituents = AmpersandDelimited | SpaceBetweenSiblings | SingleLine ,
2957
- ObjectBindingPatternElements = SingleLine | AllowTrailingComma | SpaceBetweenBraces | CommaDelimited | SpaceBetweenSiblings ,
2984
+ ObjectBindingPatternElements = SingleLine | CommaDelimited | SpaceBetweenSiblings ,
2985
+ ObjectBindingPatternElementsWithSpaceBetweenBraces = SingleLine | AllowTrailingComma | SpaceBetweenBraces | CommaDelimited | SpaceBetweenSiblings ,
2958
2986
ArrayBindingPatternElements = SingleLine | AllowTrailingComma | CommaDelimited | SpaceBetweenSiblings ,
2959
2987
ObjectLiteralExpressionProperties = PreserveLines | CommaDelimited | SpaceBetweenSiblings | SpaceBetweenBraces | Indented | Braces ,
2960
2988
ArrayLiteralExpressionElements = PreserveLines | CommaDelimited | SpaceBetweenSiblings | AllowTrailingComma | Indented | SquareBrackets ,
0 commit comments