@@ -173,8 +173,7 @@ namespace ts {
173173 const compilerOptions = newProgram . getCompilerOptions ( ) ;
174174 state . compilerOptions = compilerOptions ;
175175 // With --out or --outFile, any change affects all semantic diagnostics so no need to cache them
176- // With --isolatedModules, emitting changed file doesnt emit dependent files so we cant know of dependent files to retrieve errors so dont cache the errors
177- if ( ! compilerOptions . outFile && ! compilerOptions . out && ! compilerOptions . isolatedModules ) {
176+ if ( ! compilerOptions . outFile && ! compilerOptions . out ) {
178177 state . semanticDiagnosticsPerFile = createMap < readonly Diagnostic [ ] > ( ) ;
179178 }
180179 state . changedFilesSet = createMap < true > ( ) ;
@@ -483,16 +482,43 @@ namespace ts {
483482 return ! state . semanticDiagnosticsFromOldState . size ;
484483 }
485484
485+ function isChangedSignagure ( state : BuilderProgramState , path : Path ) {
486+ const newSignature = Debug . assertDefined ( state . currentAffectedFilesSignatures ) . get ( path ) ;
487+ const oldSignagure = Debug . assertDefined ( state . fileInfos . get ( path ) ) . signature ;
488+ return newSignature !== oldSignagure ;
489+ }
490+
486491 /**
487492 * Iterate on referencing modules that export entities from affected file
488493 */
489494 function forEachReferencingModulesOfExportOfAffectedFile ( state : BuilderProgramState , affectedFile : SourceFile , fn : ( state : BuilderProgramState , filePath : Path ) => boolean ) {
490495 // If there was change in signature (dts output) for the changed file,
491496 // then only we need to handle pending file emit
492- if ( ! state . exportedModulesMap || state . affectedFiles ! . length === 1 || ! state . changedFilesSet . has ( affectedFile . path ) ) {
497+ if ( ! state . exportedModulesMap || ! state . changedFilesSet . has ( affectedFile . path ) ) {
493498 return ;
494499 }
495500
501+ if ( ! isChangedSignagure ( state , affectedFile . path ) ) return ;
502+
503+ // Since isolated modules dont change js files, files affected by change in signature is itself
504+ // But we need to cleanup semantic diagnostics and queue dts emit for affected files
505+ if ( state . compilerOptions . isolatedModules ) {
506+ const seenFileNamesMap = createMap < true > ( ) ;
507+ seenFileNamesMap . set ( affectedFile . path , true ) ;
508+ const queue = BuilderState . getReferencedByPaths ( state , affectedFile . resolvedPath ) ;
509+ while ( queue . length > 0 ) {
510+ const currentPath = queue . pop ( ) ! ;
511+ if ( ! seenFileNamesMap . has ( currentPath ) ) {
512+ seenFileNamesMap . set ( currentPath , true ) ;
513+ const result = fn ( state , currentPath ) ;
514+ if ( result && isChangedSignagure ( state , currentPath ) ) {
515+ const currentSourceFile = Debug . assertDefined ( state . program ) . getSourceFileByPath ( currentPath ) ! ;
516+ queue . push ( ...BuilderState . getReferencedByPaths ( state , currentSourceFile . resolvedPath ) ) ;
517+ }
518+ }
519+ }
520+ }
521+
496522 Debug . assert ( ! ! state . currentAffectedFilesExportedModulesMap ) ;
497523 const seenFileAndExportsOfFile = createMap < true > ( ) ;
498524 // Go through exported modules from cache first
0 commit comments