@@ -1030,7 +1030,14 @@ namespace ts {
1030
1030
}
1031
1031
1032
1032
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
+ }
1034
1041
}
1035
1042
1036
1043
function getSyntacticDiagnosticsForFile ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
@@ -1244,17 +1251,19 @@ namespace ts {
1244
1251
} ) ;
1245
1252
}
1246
1253
1247
- function getDeclarationDiagnosticsForFile ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
1254
+ function getDeclarationDiagnosticsWorker ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
1248
1255
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 ) ;
1255
1260
} ) ;
1256
1261
}
1257
1262
1263
+ function getDeclarationDiagnosticsForFile ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
1264
+ return isDeclarationFile ( sourceFile ) ? [ ] : getDeclarationDiagnosticsWorker ( sourceFile , cancellationToken ) ;
1265
+ }
1266
+
1258
1267
function getOptionsDiagnostics ( ) : Diagnostic [ ] {
1259
1268
const allDiagnostics : Diagnostic [ ] = [ ] ;
1260
1269
addRange ( allDiagnostics , fileProcessingDiagnostics . getGlobalDiagnostics ( ) ) ;
0 commit comments