@@ -21,10 +21,14 @@ namespace ts {
2121 dry ?: boolean ;
2222 force ?: boolean ;
2323 verbose ?: boolean ;
24+
2425 /*@internal */ clean ?: boolean ;
2526 /*@internal */ watch ?: boolean ;
2627 /*@internal */ help ?: boolean ;
28+
2729 preserveWatchOutput ?: boolean ;
30+ listEmittedFiles ?: boolean ;
31+ listFiles ?: boolean ;
2832 }
2933
3034 enum BuildResultFlags {
@@ -44,8 +48,9 @@ namespace ts {
4448 SyntaxErrors = 1 << 3 ,
4549 TypeErrors = 1 << 4 ,
4650 DeclarationEmitErrors = 1 << 5 ,
51+ EmitErrors = 1 << 6 ,
4752
48- AnyErrors = ConfigFileErrors | SyntaxErrors | TypeErrors | DeclarationEmitErrors
53+ AnyErrors = ConfigFileErrors | SyntaxErrors | TypeErrors | DeclarationEmitErrors | EmitErrors
4954 }
5055
5156 export enum UpToDateStatusType {
@@ -401,6 +406,7 @@ namespace ts {
401406 const projectStatus = createFileMap < UpToDateStatus > ( toPath ) ;
402407 const missingRoots = createMap < true > ( ) ;
403408 let globalDependencyGraph : DependencyGraph | undefined ;
409+ const writeFileName = ( s : string ) => host . trace && host . trace ( s ) ;
404410
405411 // Watch state
406412 const diagnostics = createFileMap < ReadonlyArray < Diagnostic > > ( toPath ) ;
@@ -1014,35 +1020,28 @@ namespace ts {
10141020 ...program . getConfigFileParsingDiagnostics ( ) ,
10151021 ...program . getSyntacticDiagnostics ( ) ] ;
10161022 if ( syntaxDiagnostics . length ) {
1017- resultFlags |= BuildResultFlags . SyntaxErrors ;
1018- reportAndStoreErrors ( proj , syntaxDiagnostics ) ;
1019- projectStatus . setValue ( proj , { type : UpToDateStatusType . Unbuildable , reason : "Syntactic errors" } ) ;
1020- return resultFlags ;
1023+ return buildErrors ( syntaxDiagnostics , BuildResultFlags . SyntaxErrors , "Syntactic" ) ;
10211024 }
10221025
10231026 // Don't emit .d.ts if there are decl file errors
10241027 if ( getEmitDeclarations ( program . getCompilerOptions ( ) ) ) {
10251028 const declDiagnostics = program . getDeclarationDiagnostics ( ) ;
10261029 if ( declDiagnostics . length ) {
1027- resultFlags |= BuildResultFlags . DeclarationEmitErrors ;
1028- reportAndStoreErrors ( proj , declDiagnostics ) ;
1029- projectStatus . setValue ( proj , { type : UpToDateStatusType . Unbuildable , reason : "Declaration file errors" } ) ;
1030- return resultFlags ;
1030+ return buildErrors ( declDiagnostics , BuildResultFlags . DeclarationEmitErrors , "Declaration file" ) ;
10311031 }
10321032 }
10331033
10341034 // Same as above but now for semantic diagnostics
10351035 const semanticDiagnostics = program . getSemanticDiagnostics ( ) ;
10361036 if ( semanticDiagnostics . length ) {
1037- resultFlags |= BuildResultFlags . TypeErrors ;
1038- reportAndStoreErrors ( proj , semanticDiagnostics ) ;
1039- projectStatus . setValue ( proj , { type : UpToDateStatusType . Unbuildable , reason : "Semantic errors" } ) ;
1040- return resultFlags ;
1037+ return buildErrors ( semanticDiagnostics , BuildResultFlags . TypeErrors , "Semantic" ) ;
10411038 }
10421039
10431040 let newestDeclarationFileContentChangedTime = minimumDate ;
10441041 let anyDtsChanged = false ;
1045- program . emit ( /*targetSourceFile*/ undefined , ( fileName , content , writeBom , onError ) => {
1042+ let emitDiagnostics : Diagnostic [ ] | undefined ;
1043+ const reportEmitDiagnostic = ( d : Diagnostic ) => ( emitDiagnostics || ( emitDiagnostics = [ ] ) ) . push ( d ) ;
1044+ emitFilesAndReportErrors ( program , reportEmitDiagnostic , writeFileName , /*reportSummary*/ undefined , ( fileName , content , writeBom , onError ) => {
10461045 let priorChangeTime : Date | undefined ;
10471046 if ( ! anyDtsChanged && isDeclarationFile ( fileName ) ) {
10481047 // Check for unchanged .d.ts files
@@ -1062,12 +1061,23 @@ namespace ts {
10621061 }
10631062 } ) ;
10641063
1064+ if ( emitDiagnostics ) {
1065+ return buildErrors ( emitDiagnostics , BuildResultFlags . EmitErrors , "Emit" ) ;
1066+ }
1067+
10651068 const status : UpToDateStatus = {
10661069 type : UpToDateStatusType . UpToDate ,
10671070 newestDeclarationFileContentChangedTime : anyDtsChanged ? maximumDate : newestDeclarationFileContentChangedTime
10681071 } ;
10691072 projectStatus . setValue ( proj , status ) ;
10701073 return resultFlags ;
1074+
1075+ function buildErrors ( diagnostics : ReadonlyArray < Diagnostic > , errorFlags : BuildResultFlags , errorType : string ) {
1076+ resultFlags |= errorFlags ;
1077+ reportAndStoreErrors ( proj , diagnostics ) ;
1078+ projectStatus . setValue ( proj , { type : UpToDateStatusType . Unbuildable , reason : `${ errorType } errors` } ) ;
1079+ return resultFlags ;
1080+ }
10711081 }
10721082
10731083 function updateOutputTimestamps ( proj : ParsedCommandLine ) {
0 commit comments