Skip to content

Commit 8e77f40

Browse files
committed
avoid multiple passes over the program when computing diagnostics for the bundled emit
1 parent 0f67f4b commit 8e77f40

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

src/compiler/declarationEmitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace ts {
3333
export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] {
3434
const declarationDiagnostics = createDiagnosticCollection();
3535
forEachExpectedEmitFile(host, getDeclarationDiagnosticsFromFile, targetSourceFile);
36-
return declarationDiagnostics.getDiagnostics(targetSourceFile.fileName);
36+
return declarationDiagnostics.getDiagnostics(targetSourceFile ? targetSourceFile.fileName : undefined);
3737

3838
function getDeclarationDiagnosticsFromFile({ declarationFilePath }, sources: SourceFile[], isBundledEmit: boolean) {
3939
emitDeclarations(host, resolver, declarationDiagnostics, declarationFilePath, sources, isBundledEmit);

src/compiler/program.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,13 @@ namespace ts {
10301030
}
10311031

10321032
function getDeclarationDiagnostics(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
1033-
return getDiagnosticsHelper(sourceFile, getDeclarationDiagnosticsForFile, cancellationToken);
1033+
const options = program.getCompilerOptions();
1034+
if (!sourceFile || options.out || options.outFile) {
1035+
return getDeclarationDiagnosticsWorker(sourceFile, cancellationToken);
1036+
}
1037+
else {
1038+
return getDiagnosticsHelper(sourceFile, getDeclarationDiagnosticsForFile, cancellationToken);
1039+
}
10341040
}
10351041

10361042
function getSyntacticDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
@@ -1244,17 +1250,19 @@ namespace ts {
12441250
});
12451251
}
12461252

1247-
function getDeclarationDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
1253+
function getDeclarationDiagnosticsWorker(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
12481254
return runWithCancellationToken(() => {
1249-
if (!isDeclarationFile(sourceFile)) {
1250-
const resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile, cancellationToken);
1251-
// Don't actually write any files since we're just getting diagnostics.
1252-
const writeFile: WriteFileCallback = () => { };
1253-
return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile);
1254-
}
1255+
const resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile, cancellationToken);
1256+
// Don't actually write any files since we're just getting diagnostics.
1257+
const writeFile: WriteFileCallback = () => { };
1258+
return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile);
12551259
});
12561260
}
12571261

1262+
function getDeclarationDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
1263+
return isDeclarationFile(sourceFile) ? [] : getDeclarationDiagnosticsWorker(sourceFile, cancellationToken);
1264+
}
1265+
12581266
function getOptionsDiagnostics(): Diagnostic[] {
12591267
const allDiagnostics: Diagnostic[] = [];
12601268
addRange(allDiagnostics, fileProcessingDiagnostics.getGlobalDiagnostics());

0 commit comments

Comments
 (0)