@@ -87,6 +87,11 @@ module ts {
8787
8888 export function getPreEmitDiagnostics ( program : Program ) : Diagnostic [ ] {
8989 let diagnostics = program . getSyntacticDiagnostics ( ) . concat ( program . getGlobalDiagnostics ( ) ) . concat ( program . getSemanticDiagnostics ( ) ) ;
90+
91+ if ( program . getCompilerOptions ( ) . declaration ) {
92+ diagnostics . concat ( program . getDeclarationDiagnostics ( ) ) ;
93+ }
94+
9095 return sortAndDeduplicateDiagnostics ( diagnostics ) ;
9196 }
9297
@@ -178,11 +183,6 @@ module ts {
178183 return noDiagnosticsTypeChecker || ( noDiagnosticsTypeChecker = createTypeChecker ( program , /*produceDiagnostics:*/ false ) ) ;
179184 }
180185
181- function getDeclarationDiagnostics ( targetSourceFile : SourceFile ) : Diagnostic [ ] {
182- let resolver = getDiagnosticsProducingTypeChecker ( ) . getEmitResolver ( targetSourceFile ) ;
183- return ts . getDeclarationDiagnostics ( getEmitHost ( ) , resolver , targetSourceFile ) ;
184- }
185-
186186 function emit ( sourceFile ?: SourceFile , writeFileCallback ?: WriteFileCallback ) : EmitResult {
187187 // If the noEmitOnError flag is set, then check if we have any errors so far. If so,
188188 // immediately bail out.
@@ -232,6 +232,10 @@ module ts {
232232 return getDiagnosticsHelper ( sourceFile , getSemanticDiagnosticsForFile ) ;
233233 }
234234
235+ function getDeclarationDiagnostics ( sourceFile ?: SourceFile ) : Diagnostic [ ] {
236+ return getDiagnosticsHelper ( sourceFile , getDeclarationDiagnosticsForFile ) ;
237+ }
238+
235239 function getSyntacticDiagnosticsForFile ( sourceFile : SourceFile ) : Diagnostic [ ] {
236240 return sourceFile . parseDiagnostics ;
237241 }
@@ -247,6 +251,15 @@ module ts {
247251 return bindDiagnostics . concat ( checkDiagnostics ) . concat ( programDiagnostics ) ;
248252 }
249253
254+ function getDeclarationDiagnosticsForFile ( sourceFile : SourceFile ) : Diagnostic [ ] {
255+ if ( ! isDeclarationFile ( sourceFile ) ) {
256+ let resolver = getDiagnosticsProducingTypeChecker ( ) . getEmitResolver ( sourceFile ) ;
257+ // Don't actually write any files since we're just getting diagnostics.
258+ var writeFile : WriteFileCallback = ( ) => { } ;
259+ return ts . getDeclarationDiagnostics ( getEmitHost ( writeFile ) , resolver , sourceFile ) ;
260+ }
261+ }
262+
250263 function getGlobalDiagnostics ( ) : Diagnostic [ ] {
251264 let typeChecker = getDiagnosticsProducingTypeChecker ( ) ;
252265
0 commit comments