Skip to content

Commit 76d9524

Browse files
authored
Fully deprecate the symbol display builder, reimplement in terms of node builder (#18860)
* Remove SymbolWriter, give methods to EmitTextWriter * Unification of writers is done-ish * Make node builder support more flags * Write out mixins like we used to * Accept prototype-free baselines * Use instantiated constraint when building mapped type nodes * Accept better mapped type baselines * Report inaccessible this in node builder * Turns out there was a bug in our codefix, too * Symbol display builder usage falling * Replace signatureToString with a nodeBuilder solution * Replace the last internal usages of the symbol writer * Accept semicolon additions * Accept updated symbol baseline output * Start using node builder for some LS operations * Remove those pesky trailing semicolons on signatures * Get signature printing much closer to old output * Parameter lists should not be indented by default, especially when single-line * Signatures up to snuff * Type quickinfo emit is up to snuff * Start of symbol writer replacement, needs a bit more for full compat * Slightly mor accurate to old behavior * Replicate qualified name type argument output correctly * Bring back the old symbol baselines * Mostly identical to old symbol emit now * Perfectly matches old behavior thus far * Replace another usage of the symbol builder * Another usage removed * Another usage removed * Remove final uses of symbol display builder * Remove implementation and types for unused symbol display builder * Cleanup in the checker * monomorphize new emitter code * Replace emitWithSuffix * Push space character to interface with writer * List emit * Fix lack of usage of emitExpression * writeList, not printList * Remove listy writes and replace with new printer calls * Move ListFormat into types.ts * Remove most new XToString functions in favor of node builder functions * Accept API breaks * Add getSymbolDisplayBuilder polyfill * Accept updated API baseline * Move definition to make diff easier to read * Reinternalize some things * Remove trailign whitespace * Reorder for zero diff * Remove newline * Make shim mor eperfectly imitate old behavior * Style feedback * Rename reset to clear to maintain backcompat with SymbolWriter * Fix quickfix * Keep EmitTextWriter internal * Remove EmitTextWriter from public API * Mimic default name declaration emit fix * Fix tests broken by merge * use isFunctionLike * Cleanup, sync TypeFormat and NodeBuilder flags * Reorder Node initialization so pos and end are first, so a TextRange hidden class is made first to reduce future polymorphism * Use variable instead of ternary * Write helper for emitNodeWithWriter * Emitter cleanup * Cleanup whitespace, comment * Reuse printer * Raise error if display parts writer uses rawWrite * Hide writer parameter through different function instead of overload, rename function in emitter * Make less printer * fix lint
1 parent bcb9fd7 commit 76d9524

37 files changed

+1746
-1606
lines changed

src/compiler/checker.ts

Lines changed: 430 additions & 900 deletions
Large diffs are not rendered by default.

src/compiler/core.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,10 +2771,10 @@ namespace ts {
27712771
function Signature() {} // tslint:disable-line no-empty
27722772

27732773
function Node(this: Node, kind: SyntaxKind, pos: number, end: number) {
2774-
this.id = 0;
2775-
this.kind = kind;
27762774
this.pos = pos;
27772775
this.end = end;
2776+
this.kind = kind;
2777+
this.id = 0;
27782778
this.flags = NodeFlags.None;
27792779
this.modifierFlagsCache = ModifierFlags.None;
27802780
this.transformFlags = TransformFlags.None;
@@ -3046,6 +3046,10 @@ namespace ts {
30463046
return (arg: T) => f(arg) && g(arg);
30473047
}
30483048

3049+
export function or<T>(f: (arg: T) => boolean, g: (arg: T) => boolean) {
3050+
return (arg: T) => f(arg) || g(arg);
3051+
}
3052+
30493053
export function assertTypeIsNever(_: never): void { } // tslint:disable-line no-empty
30503054

30513055
export interface FileAndDirectoryExistence {

src/compiler/declarationEmitter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ namespace ts {
2020

2121
type GetSymbolAccessibilityDiagnostic = (symbolAccessibilityResult: SymbolAccessibilityResult) => SymbolAccessibilityDiagnostic;
2222

23-
interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter {
23+
interface EmitTextWriterWithSymbolWriter extends EmitTextWriter {
2424
getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic;
2525
}
2626

2727
interface SymbolAccessibilityDiagnostic {
2828
errorNode: Node;
2929
diagnosticMessage: DiagnosticMessage;
30-
typeName?: DeclarationName;
30+
typeName?: DeclarationName | QualifiedName;
3131
}
3232

3333
export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] {
@@ -358,7 +358,7 @@ namespace ts {
358358
}
359359
else {
360360
errorNameNode = declaration.name;
361-
const format = TypeFormatFlags.UseTypeOfFunction |
361+
const format = TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.WriteDefaultSymbolWithoutName |
362362
TypeFormatFlags.WriteClassExpressionAsTypeLiteral |
363363
(shouldUseResolverType ? TypeFormatFlags.AddUndefined : 0);
364364
resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, format, writer);
@@ -378,7 +378,7 @@ namespace ts {
378378
resolver.writeReturnTypeOfSignatureDeclaration(
379379
signature,
380380
enclosingDeclaration,
381-
TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.WriteClassExpressionAsTypeLiteral,
381+
TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.WriteClassExpressionAsTypeLiteral | TypeFormatFlags.WriteDefaultSymbolWithoutName,
382382
writer);
383383
errorNameNode = undefined;
384384
}
@@ -643,7 +643,7 @@ namespace ts {
643643
resolver.writeTypeOfExpression(
644644
expr,
645645
enclosingDeclaration,
646-
TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.WriteClassExpressionAsTypeLiteral,
646+
TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.WriteClassExpressionAsTypeLiteral | TypeFormatFlags.WriteDefaultSymbolWithoutName,
647647
writer);
648648
write(";");
649649
writeLine();

0 commit comments

Comments
 (0)