@@ -23,34 +23,32 @@ module ts {
23
23
return undefined ;
24
24
}
25
25
26
- interface SymbolWriter {
27
- writeKind ( text : string , kind : SymbolDisplayPartKind ) : void ;
28
- writeSymbol ( text : string , symbol : Symbol ) : void ;
29
- writeLine ( ) : void ;
30
- increaseIndent ( ) : void ;
31
- decreaseIndent ( ) : void ;
32
- clear ( ) : void ;
33
-
34
- // Called when the symbol writer encounters a symbol to write. Currently only used by the
35
- // declaration emitter to help determine if it should patch up the final declaration file
36
- // with import statements it previously saw (but chose not to emit).
37
- trackSymbol ( symbol : Symbol , enclosingDeclaration ?: Node , meaning ?: SymbolFlags ) : void ;
26
+ export interface StringSymbolWriter extends SymbolWriter {
27
+ string ( ) : string ;
38
28
}
39
29
40
- interface DisplayPartsSymbolWriter extends SymbolWriter {
41
- displayParts ( ) : SymbolDisplayPart [ ] ;
42
- }
30
+ // Pool writers to avoid needing to allocate them for every symbol we write.
31
+ var stringWriters : StringSymbolWriter [ ] = [ ] ;
32
+ export function getSingleLineStringWriter ( ) : StringSymbolWriter {
33
+ if ( stringWriters . length == 0 ) {
34
+ var str = "" ;
43
35
44
- interface StringSymbolWriter extends SymbolWriter {
45
- string ( ) : string ;
46
- }
36
+ return {
37
+ string : ( ) => str ,
38
+ writeKind : text => str += text ,
39
+ writeSymbol : text => str += text ,
40
+
41
+ // Completely ignore indentation for string writers. And map newlines to
42
+ // a single space.
43
+ writeLine : ( ) => str += " " ,
44
+ increaseIndent : ( ) => { } ,
45
+ decreaseIndent : ( ) => { } ,
46
+ clear : ( ) => str = "" ,
47
+ trackSymbol : ( ) => { }
48
+ } ;
49
+ }
47
50
48
- // TODO this should go back in services
49
- export function getSymbolDisplayPart ( text : string , kind : SymbolDisplayPartKind , symbol ?: Symbol ) : SymbolDisplayPart {
50
- return < SymbolDisplayPart > {
51
- text : text ,
52
- kind : kind
53
- } ;
51
+ return stringWriters . pop ( ) ;
54
52
}
55
53
56
54
/// fullTypeCheck denotes if this instance of the typechecker will be used to get semantic diagnostics.
@@ -92,9 +90,9 @@ module ts {
92
90
getTypeOfNode : getTypeOfNode ,
93
91
getApparentType : getApparentType ,
94
92
typeToString : typeToString ,
95
- typeToDisplayParts : typeToDisplayParts ,
93
+ writeType : writeType ,
96
94
symbolToString : symbolToString ,
97
- symbolToDisplayParts : symbolToDisplayParts ,
95
+ writeSymbol : writeSymbol ,
98
96
getAugmentedPropertiesOfApparentType : getAugmentedPropertiesOfApparentType ,
99
97
getRootSymbol : getRootSymbol ,
100
98
getContextualType : getContextualType ,
@@ -930,58 +928,6 @@ module ts {
930
928
{ accessibility : SymbolAccessibility . NotAccessible , errorSymbolName : firstIdentifierName } ;
931
929
}
932
930
933
- // Pool writers to avoid needing to allocate them for every symbol we write.
934
- var displayPartWriters : DisplayPartsSymbolWriter [ ] = [ ] ;
935
- var stringWriters : StringSymbolWriter [ ] = [ ] ;
936
-
937
- function getDisplayPartWriter ( ) : DisplayPartsSymbolWriter {
938
- if ( displayPartWriters . length == 0 ) {
939
- var displayParts : SymbolDisplayPart [ ] = [ ] ;
940
- return {
941
- displayParts : ( ) => displayParts ,
942
- writeKind : ( text , kind ) => displayParts . push ( getSymbolDisplayPart ( text , kind ) ) ,
943
- writeSymbol : ( text , symbol ) => displayParts . push ( symbolPart ( text , symbol ) ) ,
944
-
945
- // Completely ignore indentation for display part writers. And map newlines to
946
- // a single space.
947
- writeLine : ( ) => displayParts . push ( spacePart ( ) ) ,
948
- increaseIndent : ( ) => { } ,
949
- decreaseIndent : ( ) => { } ,
950
- clear : ( ) => displayParts = [ ] ,
951
- trackSymbol : ( ) => { }
952
- } ;
953
- }
954
-
955
- return displayPartWriters . pop ( ) ;
956
- }
957
-
958
- function getStringWriter ( ) : StringSymbolWriter {
959
- if ( stringWriters . length == 0 ) {
960
- var str = "" ;
961
-
962
- return {
963
- string : ( ) => str ,
964
- writeKind : text => str += text ,
965
- writeSymbol : text => str += text ,
966
-
967
- // Completely ignore indentation for string writers. And map newlines to
968
- // a single space.
969
- writeLine : ( ) => str += " " ,
970
- increaseIndent : ( ) => { } ,
971
- decreaseIndent : ( ) => { } ,
972
- clear : ( ) => str = "" ,
973
- trackSymbol : ( ) => { }
974
- } ;
975
- }
976
-
977
- return stringWriters . pop ( ) ;
978
- }
979
-
980
- function releaseDisplayPartWriter ( writer : DisplayPartsSymbolWriter ) {
981
- writer . clear ( ) ;
982
- displayPartWriters . push ( writer ) ;
983
- }
984
-
985
931
function releaseStringWriter ( writer : StringSymbolWriter ) {
986
932
writer . clear ( )
987
933
stringWriters . push ( writer ) ;
@@ -1004,7 +950,7 @@ module ts {
1004
950
}
1005
951
1006
952
function symbolToString ( symbol : Symbol , enclosingDeclaration ?: Node , meaning ?: SymbolFlags ) : string {
1007
- var writer = getStringWriter ( ) ;
953
+ var writer = getSingleLineStringWriter ( ) ;
1008
954
writeSymbol ( symbol , writer , enclosingDeclaration , meaning ) ;
1009
955
1010
956
var result = writer . string ( ) ;
@@ -1013,16 +959,6 @@ module ts {
1013
959
return result ;
1014
960
}
1015
961
1016
- function symbolToDisplayParts ( symbol : Symbol , enclosingDeclaration ?: Node , meaning ?: SymbolFlags ) : SymbolDisplayPart [ ] {
1017
- var writer = getDisplayPartWriter ( ) ;
1018
- writeSymbol ( symbol , writer , enclosingDeclaration , meaning ) ;
1019
-
1020
- var result = writer . displayParts ( ) ;
1021
- releaseDisplayPartWriter ( writer ) ;
1022
-
1023
- return result ;
1024
- }
1025
-
1026
962
// Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope
1027
963
// Meaning needs to be specified if the enclosing declaration is given
1028
964
function writeSymbol ( symbol : Symbol , writer : SymbolWriter , enclosingDeclaration ?: Node , meaning ?: SymbolFlags ) : void {
@@ -1099,12 +1035,8 @@ module ts {
1099
1035
return writeSymbolName ( symbol ) ;
1100
1036
}
1101
1037
1102
- function writeSymbolToTextWriter ( symbol : Symbol , enclosingDeclaration : Node , meaning : SymbolFlags , writer : TextWriter ) {
1103
- writer . write ( symbolToString ( symbol , enclosingDeclaration , meaning ) ) ;
1104
- }
1105
-
1106
1038
function typeToString ( type : Type , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags ) : string {
1107
- var writer = getStringWriter ( ) ;
1039
+ var writer = getSingleLineStringWriter ( ) ;
1108
1040
writeType ( type , writer , enclosingDeclaration , flags ) ;
1109
1041
1110
1042
var result = writer . string ( ) ;
@@ -1118,16 +1050,6 @@ module ts {
1118
1050
return result ;
1119
1051
}
1120
1052
1121
- function typeToDisplayParts ( type : Type , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags ) : SymbolDisplayPart [ ] {
1122
- var writer = getDisplayPartWriter ( ) ;
1123
- writeType ( type , writer , enclosingDeclaration , flags ) ;
1124
-
1125
- var result = writer . displayParts ( ) ;
1126
- releaseDisplayPartWriter ( writer ) ;
1127
-
1128
- return result ;
1129
- }
1130
-
1131
1053
function writeType ( type : Type , writer : SymbolWriter , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags ) {
1132
1054
var typeStack : Type [ ] ;
1133
1055
return writeType ( type , /*allowFunctionOrConstructorTypeLiteral*/ true ) ;
@@ -7620,34 +7542,17 @@ module ts {
7620
7542
return undefined ;
7621
7543
}
7622
7544
7623
- // Create a single instance that we can wrap the underlying emitter TextWriter with. That
7624
- // way we don't have to allocate a new wrapper every time writeTypeAtLocation and
7625
- // writeReturnTypeOfSignatureDeclaration are called.
7626
- var emitSymbolWriter = {
7627
- writer : < TextWriter > undefined ,
7628
-
7629
- writeKind : function ( text : string ) { this . writer . write ( text ) } ,
7630
- writeSymbol : function ( text : string ) { this . writer . write ( text ) } ,
7631
- writeLine : function ( ) { this . writer . writeLine ( ) } ,
7632
- increaseIndent : function ( ) { this . writer . increaseIndent ( ) } ,
7633
- decreaseIndent : function ( ) { this . writer . decreaseIndent ( ) } ,
7634
- clear : function ( ) { } ,
7635
- trackSymbol : function ( symbol : Symbol , declaration : Node , meaning : SymbolFlags ) { this . writer . trackSymbol ( symbol , declaration , meaning ) }
7636
- } ;
7637
-
7638
- function writeTypeAtLocation ( location : Node , enclosingDeclaration : Node , flags : TypeFormatFlags , writer : TextWriter ) {
7545
+ function writeTypeAtLocation ( location : Node , enclosingDeclaration : Node , flags : TypeFormatFlags , writer : SymbolWriter ) {
7639
7546
// Get type of the symbol if this is the valid symbol otherwise get type at location
7640
7547
var symbol = getSymbolOfNode ( location ) ;
7641
7548
var type = symbol && ! ( symbol . flags & SymbolFlags . TypeLiteral ) ? getTypeOfSymbol ( symbol ) : getTypeFromTypeNode ( location ) ;
7642
7549
7643
- emitSymbolWriter . writer = writer ;
7644
- writeType ( type , emitSymbolWriter , enclosingDeclaration , flags ) ;
7550
+ writeType ( type , writer , enclosingDeclaration , flags ) ;
7645
7551
}
7646
7552
7647
- function writeReturnTypeOfSignatureDeclaration ( signatureDeclaration : SignatureDeclaration , enclosingDeclaration : Node , flags : TypeFormatFlags , writer : TextWriter ) {
7553
+ function writeReturnTypeOfSignatureDeclaration ( signatureDeclaration : SignatureDeclaration , enclosingDeclaration : Node , flags : TypeFormatFlags , writer : SymbolWriter ) {
7648
7554
var signature = getSignatureFromDeclaration ( signatureDeclaration ) ;
7649
- emitSymbolWriter . writer = writer ;
7650
- writeType ( getReturnTypeOfSignature ( signature ) , emitSymbolWriter , enclosingDeclaration , flags ) ;
7555
+ writeType ( getReturnTypeOfSignature ( signature ) , writer , enclosingDeclaration , flags ) ;
7651
7556
}
7652
7557
7653
7558
function invokeEmitter ( targetSourceFile ?: SourceFile ) {
@@ -7705,49 +7610,4 @@ module ts {
7705
7610
7706
7611
return checker ;
7707
7612
}
7708
-
7709
- export function spacePart ( ) {
7710
- return getSymbolDisplayPart ( " " , SymbolDisplayPartKind . space , undefined ) ;
7711
- }
7712
-
7713
- export function keywordPart ( kind : SyntaxKind ) {
7714
- return getSymbolDisplayPart ( tokenToString ( kind ) , SymbolDisplayPartKind . keyword , undefined ) ;
7715
- }
7716
-
7717
- export function punctuationPart ( kind : SyntaxKind ) {
7718
- return getSymbolDisplayPart ( tokenToString ( kind ) , SymbolDisplayPartKind . punctuation , undefined ) ;
7719
- }
7720
-
7721
- export function operatorPart ( kind : SyntaxKind ) {
7722
- return getSymbolDisplayPart ( tokenToString ( kind ) , SymbolDisplayPartKind . operator , undefined ) ;
7723
- }
7724
-
7725
- export function textPart ( text : string ) {
7726
- return getSymbolDisplayPart ( text , SymbolDisplayPartKind . text , undefined ) ;
7727
- }
7728
-
7729
- export function symbolPart ( text : string , symbol : Symbol ) {
7730
- return getSymbolDisplayPart ( text , displayPartKind ( symbol ) , symbol )
7731
- }
7732
-
7733
- function displayPartKind ( symbol : Symbol ) : SymbolDisplayPartKind {
7734
- var flags = symbol . flags ;
7735
-
7736
- if ( flags & SymbolFlags . Variable ) {
7737
- return symbol . declarations && symbol . declarations . length > 0 && symbol . declarations [ 0 ] . kind === SyntaxKind . Parameter
7738
- ? SymbolDisplayPartKind . parameterName
7739
- : SymbolDisplayPartKind . localName ;
7740
- }
7741
- else if ( flags & SymbolFlags . Property ) { return SymbolDisplayPartKind . propertyName ; }
7742
- else if ( flags & SymbolFlags . EnumMember ) { return SymbolDisplayPartKind . enumMemberName ; }
7743
- else if ( flags & SymbolFlags . Function ) { return SymbolDisplayPartKind . functionName ; }
7744
- else if ( flags & SymbolFlags . Class ) { return SymbolDisplayPartKind . className ; }
7745
- else if ( flags & SymbolFlags . Interface ) { return SymbolDisplayPartKind . interfaceName ; }
7746
- else if ( flags & SymbolFlags . Enum ) { return SymbolDisplayPartKind . enumName ; }
7747
- else if ( flags & SymbolFlags . Module ) { return SymbolDisplayPartKind . moduleName ; }
7748
- else if ( flags & SymbolFlags . Method ) { return SymbolDisplayPartKind . methodName ; }
7749
- else if ( flags & SymbolFlags . TypeParameter ) { return SymbolDisplayPartKind . typeParameterName ; }
7750
-
7751
- return SymbolDisplayPartKind . text ;
7752
- }
7753
7613
}
0 commit comments