Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 29 additions & 36 deletions packages/typescript/src/api/async/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ export interface TranspileOptions {

export interface TranspileOutput {
outputText: string;
diagnostics?: readonly Diagnostic[];
sourceMapText?: string;
diagnostics?: readonly Diagnostic[] | undefined;
sourceMapText?: string | undefined;
}

// @sync-only-start
Expand Down Expand Up @@ -515,8 +515,8 @@ export class API<FromLSP extends boolean = false> implements FormatDiagnosticsHo
const data: CreateProgramResponse = await this.client.apiRequest("createProgram", {
rootFiles,
createProgramOptions,
...(oldProgram ? { oldProgram: { snapshot: oldProgram.snapshotId, project: oldProgram.getProject().id } } : {}),
...(fileChanges ? { fileChanges } : {}),
oldProgram: oldProgram ? { snapshot: oldProgram.snapshotId, project: oldProgram.getProject().id } : undefined,
fileChanges,
});
if (!data.project) {
throw new Error("createProgram did not return a project");
Expand Down Expand Up @@ -1116,8 +1116,8 @@ export class LanguageService {
project: this.project.id,
file: document,
position,
...(options?.triggerCharacter !== undefined ? { triggerCharacter: options.triggerCharacter } : {}),
...(options?.includeSymbol !== undefined ? { includeSymbol: options.includeSymbol } : {}),
triggerCharacter: options?.triggerCharacter,
includeSymbol: options?.includeSymbol,
});
if (!data) return undefined;
return {
Expand Down Expand Up @@ -1324,7 +1324,7 @@ export class Program implements FormatDiagnosticsHost {
const data = await this.client.apiRequest("getSyntacticDiagnostics", {
snapshot: this.snapshotId,
project: this.project.id,
...(files !== undefined ? { files } : {}),
files,
});
return data ?? [];
}
Expand All @@ -1340,7 +1340,7 @@ export class Program implements FormatDiagnosticsHost {
const data = await this.client.apiRequest("getBindDiagnostics", {
snapshot: this.snapshotId,
project: this.project.id,
...(files !== undefined ? { files } : {}),
files,
});
return data ?? [];
}
Expand All @@ -1356,7 +1356,7 @@ export class Program implements FormatDiagnosticsHost {
const data = await this.client.apiRequest("getSemanticDiagnostics", {
snapshot: this.snapshotId,
project: this.project.id,
...(files !== undefined ? { files } : {}),
files,
});
return data ?? [];
}
Expand All @@ -1372,7 +1372,7 @@ export class Program implements FormatDiagnosticsHost {
const data = await this.client.apiRequest("getSuggestionDiagnostics", {
snapshot: this.snapshotId,
project: this.project.id,
...(files !== undefined ? { files } : {}),
files,
});
return data ?? [];
}
Expand All @@ -1388,7 +1388,7 @@ export class Program implements FormatDiagnosticsHost {
const data = await this.client.apiRequest("getDeclarationDiagnostics", {
snapshot: this.snapshotId,
project: this.project.id,
...(files !== undefined ? { files } : {}),
files,
});
return data ?? [];
}
Expand Down Expand Up @@ -1435,7 +1435,7 @@ export class Program implements FormatDiagnosticsHost {
const response = await this.client.apiRequest("emit", {
snapshot: this.snapshotId,
project: this.project.id,
...(emitOnly !== undefined ? { emitOnly } : {}),
emitOnly,
});
const fileSystem = response.emittedFilesContents.length
? {
Expand All @@ -1458,7 +1458,7 @@ export class Program implements FormatDiagnosticsHost {
const response = await this.client.apiRequest("emitToString", {
snapshot: this.snapshotId,
project: this.project.id,
...(emitOnly !== undefined ? { emitOnly } : {}),
emitOnly,
});
return toEmitOutput(response);
}
Expand Down Expand Up @@ -1741,14 +1741,10 @@ export class Checker {
project: this.project.id,
name,
meaning,
...(isNode ? { location: getNodeId(location as Node) } : {}),
...(!isNode && location
? {
file: (location as DocumentPosition).document,
position: (location as DocumentPosition).position,
}
: {}),
...(excludeGlobals !== undefined ? { excludeGlobals } : {}),
location: isNode ? getNodeId(location as Node) : undefined,
file: !isNode && location ? (location as DocumentPosition).document : undefined,
position: !isNode && location ? (location as DocumentPosition).position : undefined,
excludeGlobals,
});
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
}
Expand All @@ -1763,12 +1759,9 @@ export class Checker {
snapshot: this.snapshotId,
project: this.project.id,
meaning,
...(isNode
? { location: getNodeId(location as Node) }
: {
file: (location as DocumentPosition).document,
position: (location as DocumentPosition).position,
}),
location: isNode ? getNodeId(location as Node) : undefined,
file: isNode ? undefined : (location as DocumentPosition).document,
position: isNode ? undefined : (location as DocumentPosition).position,
});
return data ? data.map(d => this.objectRegistry.getOrCreateSymbol(d)) : [];
}
Expand Down Expand Up @@ -1932,8 +1925,8 @@ export class Checker {
snapshot: this.snapshotId,
project: this.project.id,
type: type.id,
...(enclosingDeclaration ? { location: getNodeId(enclosingDeclaration) } : {}),
...(flags !== undefined ? { flags } : {}),
location: enclosingDeclaration ? getNodeId(enclosingDeclaration) : undefined,
flags,
});
if (!binaryData) return undefined;
return decodeNode(binaryData) as TypeNode;
Expand All @@ -1945,8 +1938,8 @@ export class Checker {
project: this.project.id,
signature: signature.id,
kind,
...(enclosingDeclaration ? { location: getNodeId(enclosingDeclaration) } : {}),
...(flags !== undefined ? { flags } : {}),
location: enclosingDeclaration ? getNodeId(enclosingDeclaration) : undefined,
flags,
});
if (!binaryData) return undefined;
return decodeNode(binaryData) as Node;
Expand All @@ -1957,8 +1950,8 @@ export class Checker {
snapshot: this.snapshotId,
project: this.project.id,
type: type.id,
...(enclosingDeclaration ? { location: getNodeId(enclosingDeclaration) } : {}),
...(flags !== undefined ? { flags } : {}),
location: enclosingDeclaration ? getNodeId(enclosingDeclaration) : undefined,
flags,
});
if (typeof result !== "string") throw new TypeError("typeToString returned a non-string result");
return result;
Expand Down Expand Up @@ -2296,9 +2289,9 @@ export class Emitter {
const base64 = uint8ArrayToBase64(encoded);
return this.client.apiRequest("printNode", {
data: base64,
...(options.preserveSourceNewlines !== undefined ? { preserveSourceNewlines: options.preserveSourceNewlines } : {}),
...(options.neverAsciiEscape !== undefined ? { neverAsciiEscape: options.neverAsciiEscape } : {}),
...(options.terminateUnterminatedLiterals !== undefined ? { terminateUnterminatedLiterals: options.terminateUnterminatedLiterals } : {}),
preserveSourceNewlines: options.preserveSourceNewlines,
neverAsciiEscape: options.neverAsciiEscape,
terminateUnterminatedLiterals: options.terminateUnterminatedLiterals,
});
}
}
Expand Down
Loading