@@ -68,8 +68,8 @@ namespace ts {
6868 return getOrCreateValueFromConfigFileMap < ESMap < string , T > > ( configFileMap , resolved , ( ) => new Map ( ) ) ;
6969 }
7070
71- function newer ( date1 : Date , date2 : Date ) : Date {
72- return date2 > date1 ? date2 : date1 ;
71+ function newer ( date1 : Date | undefined , date2 : Date ) : Date | undefined {
72+ return date1 ? date2 > date1 ? date2 : date1 : date2 ;
7373 }
7474
7575 export type ReportEmitErrorSummary = ( errorCount : number , filesInError : ( ReportFileInError | undefined ) [ ] ) => void ;
@@ -962,35 +962,28 @@ namespace ts {
962962 // Actual Emit
963963 const { host, compilerHost } = state ;
964964 let resultFlags = BuildResultFlags . DeclarationOutputUnchanged ;
965- let newestDeclarationFileContentChangedTime = minimumDate ;
966- let anyDtsChanged = false ;
965+ let newestDeclarationFileContentChangedTime : Date | undefined ;
967966 const emitterDiagnostics = createDiagnosticCollection ( ) ;
968967 const emittedOutputs = new Map < Path , string > ( ) ;
969968 outputFiles . forEach ( ( { name, text, writeByteOrderMark } ) => {
970- let priorChangeTime : Date | undefined ;
971- if ( ! anyDtsChanged && isDeclarationFileName ( name ) ) {
969+ if ( resultFlags === BuildResultFlags . DeclarationOutputUnchanged && isDeclarationFileName ( name ) ) {
972970 // Check for unchanged .d.ts files
973971 if ( state . readFileWithCache ( name ) === text ) {
974- priorChangeTime = getModifiedTime ( host , name ) ;
972+ newestDeclarationFileContentChangedTime = newer ( newestDeclarationFileContentChangedTime , getModifiedTime ( host , name ) ) ;
975973 }
976974 else {
977975 resultFlags &= ~ BuildResultFlags . DeclarationOutputUnchanged ;
978- anyDtsChanged = true ;
979976 }
980977 }
981978
982979 emittedOutputs . set ( toPath ( state , name ) , name ) ;
983980 writeFile ( writeFileCallback ? { writeFile : writeFileCallback } : compilerHost , emitterDiagnostics , name , text , writeByteOrderMark ) ;
984- if ( priorChangeTime !== undefined ) {
985- newestDeclarationFileContentChangedTime = newer ( priorChangeTime , newestDeclarationFileContentChangedTime ) ;
986- }
987981 } ) ;
988982
989983 finishEmit (
990984 emitterDiagnostics ,
991985 emittedOutputs ,
992986 newestDeclarationFileContentChangedTime ,
993- /*newestDeclarationFileContentChangedTimeIsMaximumDate*/ anyDtsChanged ,
994987 outputFiles . length ? outputFiles [ 0 ] . name : getFirstProjectOutput ( config , ! host . useCaseSensitiveFileNames ( ) ) ,
995988 resultFlags
996989 ) ;
@@ -1018,8 +1011,7 @@ namespace ts {
10181011 function finishEmit (
10191012 emitterDiagnostics : DiagnosticCollection ,
10201013 emittedOutputs : ESMap < Path , string > ,
1021- priorNewestUpdateTime : Date ,
1022- newestDeclarationFileContentChangedTimeIsMaximumDate : boolean ,
1014+ newestDeclarationFileContentChangedTime : Date | undefined ,
10231015 oldestOutputFileName : string ,
10241016 resultFlags : BuildResultFlags
10251017 ) {
@@ -1042,13 +1034,12 @@ namespace ts {
10421034 }
10431035
10441036 // Update time stamps for rest of the outputs
1045- const newestDeclarationFileContentChangedTime = updateOutputTimestampsWorker ( state , config , priorNewestUpdateTime , Diagnostics . Updating_unchanged_output_timestamps_of_project_0 , emittedOutputs ) ;
1037+ const anyDtsChange = ! ( resultFlags & BuildResultFlags . DeclarationOutputUnchanged ) ;
1038+ newestDeclarationFileContentChangedTime = updateOutputTimestampsWorker ( state , config , anyDtsChange , Diagnostics . Updating_unchanged_output_timestamps_of_project_0 , newestDeclarationFileContentChangedTime , emittedOutputs ) ;
10461039 state . diagnostics . delete ( projectPath ) ;
10471040 state . projectStatus . set ( projectPath , {
10481041 type : UpToDateStatusType . UpToDate ,
1049- newestDeclarationFileContentChangedTime : newestDeclarationFileContentChangedTimeIsMaximumDate ?
1050- maximumDate :
1051- newestDeclarationFileContentChangedTime ,
1042+ newestDeclarationFileContentChangedTime : anyDtsChange ? undefined : newestDeclarationFileContentChangedTime ,
10521043 oldestOutputFileName
10531044 } ) ;
10541045 afterProgramDone ( state , program , config ) ;
@@ -1107,8 +1098,7 @@ namespace ts {
11071098 const emitDiagnostics = finishEmit (
11081099 emitterDiagnostics ,
11091100 emittedOutputs ,
1110- minimumDate ,
1111- /*newestDeclarationFileContentChangedTimeIsMaximumDate*/ false ,
1101+ /*newestDeclarationFileContentChangedTime*/ undefined ,
11121102 outputFiles [ 0 ] . name ,
11131103 BuildResultFlags . DeclarationOutputUnchanged
11141104 ) ;
@@ -1419,7 +1409,7 @@ namespace ts {
14191409 // Now see if all outputs are newer than the newest input
14201410 let oldestOutputFileName = "(none)" ;
14211411 let oldestOutputFileTime = maximumDate ;
1422- let newestDeclarationFileContentChangedTime = minimumDate ;
1412+ let newestDeclarationFileContentChangedTime ;
14231413 if ( ! force ) {
14241414 for ( const output of outputs ) {
14251415 // Output is missing; can stop checking
@@ -1548,8 +1538,8 @@ namespace ts {
15481538 return actual ;
15491539 }
15501540
1551- function updateOutputTimestampsWorker ( state : SolutionBuilderState , proj : ParsedCommandLine , priorNewestUpdateTime : Date , verboseMessage : DiagnosticMessage , skipOutputs ?: ESMap < Path , string > ) {
1552- if ( proj . options . noEmit ) return priorNewestUpdateTime ;
1541+ function updateOutputTimestampsWorker ( state : SolutionBuilderState , proj : ParsedCommandLine , anyDtsChange : boolean , verboseMessage : DiagnosticMessage , newestDeclarationFileContentChangedTime ?: Date , skipOutputs ?: ESMap < Path , string > ) {
1542+ if ( proj . options . noEmit ) return undefined ;
15531543 const { host } = state ;
15541544 const outputs = getAllProjectOutputs ( proj , ! host . useCaseSensitiveFileNames ( ) ) ;
15551545 if ( ! skipOutputs || outputs . length !== skipOutputs . size ) {
@@ -1565,22 +1555,22 @@ namespace ts {
15651555 reportStatus ( state , verboseMessage , proj . options . configFilePath ! ) ;
15661556 }
15671557
1568- if ( isDeclarationFileName ( file ) ) {
1569- priorNewestUpdateTime = newer ( priorNewestUpdateTime , getModifiedTime ( host , file ) ) ;
1558+ if ( ! anyDtsChange && isDeclarationFileName ( file ) ) {
1559+ newestDeclarationFileContentChangedTime = newer ( newestDeclarationFileContentChangedTime , getModifiedTime ( host , file ) ) ;
15701560 }
15711561
15721562 host . setModifiedTime ( file , now ) ;
15731563 }
15741564 }
15751565
1576- return priorNewestUpdateTime ;
1566+ return newestDeclarationFileContentChangedTime ;
15771567 }
15781568
15791569 function updateOutputTimestamps ( state : SolutionBuilderState , proj : ParsedCommandLine , resolvedPath : ResolvedConfigFilePath ) {
15801570 if ( state . options . dry ) {
15811571 return reportStatus ( state , Diagnostics . A_non_dry_build_would_update_timestamps_for_output_of_project_0 , proj . options . configFilePath ! ) ;
15821572 }
1583- const priorNewestUpdateTime = updateOutputTimestampsWorker ( state , proj , minimumDate , Diagnostics . Updating_output_timestamps_of_project_0 ) ;
1573+ const priorNewestUpdateTime = updateOutputTimestampsWorker ( state , proj , /*anyDtsChange*/ false , Diagnostics . Updating_output_timestamps_of_project_0 ) ;
15841574 state . projectStatus . set ( resolvedPath , {
15851575 type : UpToDateStatusType . UpToDate ,
15861576 newestDeclarationFileContentChangedTime : priorNewestUpdateTime ,
0 commit comments