Skip to content

Commit d70e003

Browse files
Clean up symbol writing API.
1 parent f97bb60 commit d70e003

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ module ts {
2424
}
2525

2626
interface SymbolWriter {
27-
write(text: string, kind: SymbolDisplayPartKind, symbol: Symbol): void;
28-
displayPartKind(symbol: Symbol): SymbolDisplayPartKind;
27+
writeKind(text: string, kind: SymbolDisplayPartKind): void;
28+
writeSymbol(text: string, symbol: Symbol): void;
2929
clear(): void;
3030
}
3131

@@ -911,6 +911,7 @@ module ts {
911911
{ accessibility: SymbolAccessibility.NotAccessible, errorSymbolName: firstIdentifierName };
912912
}
913913

914+
// Pool writers to avoid needing to allocate them for every symbol we write.
914915
var displayPartWriters: DisplayPartsSymbolWriter[] = [];
915916
var stringWriters: StringSymbolWriter[] = [];
916917

@@ -940,9 +941,9 @@ module ts {
940941
var displayParts: SymbolDisplayPart[] = [];
941942
return {
942943
displayParts: () => displayParts,
943-
write: (text, kind, symbol) => displayParts.push({ text: text, kind: kind, symbol: symbol }),
944+
writeKind: (text, kind) => displayParts.push({ text: text, kind: kind, symbol: undefined }),
945+
writeSymbol: (text, symbol) => displayParts.push({ text: text, kind: displayPartKind(symbol), symbol: symbol }),
944946
clear: () => displayParts = [],
945-
displayPartKind: displayPartKind
946947
};
947948
}
948949

@@ -955,9 +956,9 @@ module ts {
955956

956957
return {
957958
string: () => str,
958-
write: text => str += text,
959+
writeKind: (text, kind) => str += text,
960+
writeSymbol: (text, symbol) => str += text,
959961
clear: () => str = "",
960-
displayPartKind: (symbol: Symbol): SymbolDisplayPartKind => undefined
961962
};
962963
}
963964

@@ -1001,12 +1002,12 @@ module ts {
10011002
if (symbol.declarations && symbol.declarations.length > 0) {
10021003
var declaration = symbol.declarations[0];
10031004
if (declaration.name) {
1004-
writer.write(identifierToString(declaration.name), writer.displayPartKind(symbol), symbol);
1005+
writer.writeSymbol(identifierToString(declaration.name), symbol);
10051006
return;
10061007
}
10071008
}
10081009

1009-
writer.write(symbol.name, writer.displayPartKind(symbol), symbol);
1010+
writer.writeSymbol(symbol.name, symbol);
10101011
}
10111012

10121013
var needsDot = false;
@@ -1026,7 +1027,7 @@ module ts {
10261027
if (accessibleSymbolChain) {
10271028
for (var i = 0, n = accessibleSymbolChain.length; i < n; i++) {
10281029
if (needsDot) {
1029-
writer.write(".", SymbolDisplayPartKind.Punctuation, /*symbol:*/ undefined);
1030+
writer.writeKind(".", SymbolDisplayPartKind.Punctuation);
10301031
}
10311032

10321033
writeSymbolName(accessibleSymbolChain[i]);
@@ -1040,7 +1041,7 @@ module ts {
10401041
}
10411042

10421043
if (needsDot) {
1043-
writer.write(".", SymbolDisplayPartKind.Punctuation, /*symbol:*/ undefined);
1044+
writer.writeKind(".", SymbolDisplayPartKind.Punctuation);
10441045
}
10451046

10461047
writeSymbolName(symbol);

0 commit comments

Comments
 (0)