@@ -1030,7 +1030,14 @@ namespace ts {
10301030 }
10311031
10321032 function getDeclarationDiagnostics ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
1033- return getDiagnosticsHelper ( sourceFile , getDeclarationDiagnosticsForFile , cancellationToken ) ;
1033+ const options = program . getCompilerOptions ( ) ;
1034+ // collect diagnostics from the program only once if either no source file was specified or out/outFile is set (bundled emit)
1035+ if ( ! sourceFile || options . out || options . outFile ) {
1036+ return getDeclarationDiagnosticsWorker ( sourceFile , cancellationToken ) ;
1037+ }
1038+ else {
1039+ return getDiagnosticsHelper ( sourceFile , getDeclarationDiagnosticsForFile , cancellationToken ) ;
1040+ }
10341041 }
10351042
10361043 function getSyntacticDiagnosticsForFile ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
@@ -1244,17 +1251,19 @@ namespace ts {
12441251 } ) ;
12451252 }
12461253
1247- function getDeclarationDiagnosticsForFile ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
1254+ function getDeclarationDiagnosticsWorker ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
12481255 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- }
1256+ const resolver = getDiagnosticsProducingTypeChecker ( ) . getEmitResolver ( sourceFile , cancellationToken ) ;
1257+ // Don't actually write any files since we're just getting diagnostics.
1258+ const writeFile : WriteFileCallback = ( ) => { } ;
1259+ return ts . getDeclarationDiagnostics ( getEmitHost ( writeFile ) , resolver , sourceFile ) ;
12551260 } ) ;
12561261 }
12571262
1263+ function getDeclarationDiagnosticsForFile ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
1264+ return isDeclarationFile ( sourceFile ) ? [ ] : getDeclarationDiagnosticsWorker ( sourceFile , cancellationToken ) ;
1265+ }
1266+
12581267 function getOptionsDiagnostics ( ) : Diagnostic [ ] {
12591268 const allDiagnostics : Diagnostic [ ] = [ ] ;
12601269 addRange ( allDiagnostics , fileProcessingDiagnostics . getGlobalDiagnostics ( ) ) ;
0 commit comments