@@ -340,7 +340,7 @@ namespace ts {
340340 // Set the next affected file as seen and remove the cached semantic diagnostics
341341 state . affectedFilesIndex = affectedFilesIndex ;
342342 cleanSemanticDiagnosticsOfAffectedFile ( state , affectedFile ) ;
343- handleDtsMayChangeOfAffectedFile ( state , affectedFile )
343+ handleDtsMayChangeOfAffectedFile ( state , affectedFile , cancellationToken , computeHash ) ;
344344 return affectedFile ;
345345 }
346346 seenAffectedFiles . set ( affectedFile . path , true ) ;
@@ -451,11 +451,7 @@ namespace ts {
451451 * Add files, that are referencing modules that export entities from affected file as pending emit since dts may change
452452 * Similar to cleanSemanticDiagnosticsOfAffectedFile
453453 */
454- function handleDtsMayChangeOfAffectedFile ( state : BuilderProgramState , affectedFile : SourceFile ) {
455- // If not dts emit, nothing more to do
456- if ( ! getEmitDeclarations ( state . compilerOptions ) ) {
457- return ;
458- }
454+ function handleDtsMayChangeOfAffectedFile ( state : BuilderProgramState , affectedFile : SourceFile , cancellationToken : CancellationToken | undefined , computeHash : BuilderState . ComputeHash ) {
459455
460456 // If affected files is everything except default librarry, then nothing more to do
461457 if ( state . allFilesExcludingDefaultLibraryFile === state . affectedFiles ) {
@@ -468,10 +464,26 @@ namespace ts {
468464 return ;
469465 }
470466
471- forEachReferencingModulesOfExportOfAffectedFile ( state , affectedFile , ( state , filePath ) => {
472- addToAffectedFilesPendingEmit ( state , [ filePath ] ) ;
473- return false ;
474- } ) ;
467+ forEachReferencingModulesOfExportOfAffectedFile ( state , affectedFile , ( state , path ) => handleDtsMayChangeOf ( state , path , cancellationToken , computeHash ) ) ;
468+ }
469+
470+ /**
471+ * Handle the dts may change, so they need to be added to pending emit if dts emit is enabled,
472+ * Also we need to make sure signature is updated for these files
473+ */
474+ function handleDtsMayChangeOf ( state : BuilderProgramState , path : Path , cancellationToken : CancellationToken | undefined , computeHash : BuilderState . ComputeHash ) {
475+ if ( ! state . changedFilesSet . has ( path ) ) {
476+ const program = Debug . assertDefined ( state . program ) ;
477+ const sourceFile = program . getSourceFileByPath ( path ) ;
478+ if ( sourceFile ) {
479+ BuilderState . updateShapeSignature ( state , program , sourceFile , Debug . assertDefined ( state . currentAffectedFilesSignatures ) , cancellationToken , computeHash , state . currentAffectedFilesExportedModulesMap ) ;
480+ // If not dts emit, nothing more to do
481+ if ( getEmitDeclarations ( state . compilerOptions ) ) {
482+ addToAffectedFilesPendingEmit ( state , [ path ] ) ;
483+ }
484+ }
485+ }
486+ return false ;
475487 }
476488
477489 /**
0 commit comments