@@ -540,6 +540,18 @@ namespace ts {
540
540
return newSignature !== oldSignature ;
541
541
}
542
542
543
+ function forEachKeyOfExportedModulesMap ( state : BuilderProgramState , filePath : Path , fn : ( exportedFromPath : Path ) => void ) {
544
+ // Go through exported modules from cache first
545
+ state . currentAffectedFilesExportedModulesMap ! . getKeys ( filePath ) ?. forEach ( fn ) ;
546
+ // If exported from path is not from cache and exported modules has path, all files referencing file exported from are affected
547
+ state . exportedModulesMap ! . getKeys ( filePath ) ?. forEach ( exportedFromPath =>
548
+ // If the cache had an updated value, skip
549
+ ! state . currentAffectedFilesExportedModulesMap ! . hasKey ( exportedFromPath ) &&
550
+ ! state . currentAffectedFilesExportedModulesMap ! . deletedKeys ( ) ?. has ( exportedFromPath ) &&
551
+ fn ( exportedFromPath )
552
+ ) ;
553
+ }
554
+
543
555
/**
544
556
* Iterate on referencing modules that export entities from affected file and delete diagnostics and add pending emit
545
557
*/
@@ -578,58 +590,22 @@ namespace ts {
578
590
const seenFileAndExportsOfFile = new Set < string > ( ) ;
579
591
// Go through exported modules from cache first
580
592
// If exported modules has path, all files referencing file exported from are affected
581
- state . currentAffectedFilesExportedModulesMap . getKeys ( affectedFile . resolvedPath ) ?. forEach ( exportedFromPath =>
582
- handleDtsMayChangeOfFilesReferencingPath (
583
- state ,
584
- exportedFromPath ,
585
- seenFileAndExportsOfFile ,
586
- cancellationToken ,
587
- computeHash ,
588
- host
589
- )
590
- ) ;
591
-
592
- // If exported from path is not from cache and exported modules has path, all files referencing file exported from are affected
593
- state . exportedModulesMap . getKeys ( affectedFile . resolvedPath ) ?. forEach ( exportedFromPath =>
594
- // If the cache had an updated value, skip
595
- ! state . currentAffectedFilesExportedModulesMap ! . hasKey ( exportedFromPath ) &&
596
- ! state . currentAffectedFilesExportedModulesMap ! . deletedKeys ( ) ?. has ( exportedFromPath ) &&
597
- handleDtsMayChangeOfFilesReferencingPath (
598
- state ,
599
- exportedFromPath ,
600
- seenFileAndExportsOfFile ,
601
- cancellationToken ,
602
- computeHash ,
603
- host
604
- )
605
- ) ;
606
- }
607
-
608
- /**
609
- * Iterate on files referencing referencedPath and handle the dts emit and semantic diagnostics of the file
610
- */
611
- function handleDtsMayChangeOfFilesReferencingPath (
612
- state : BuilderProgramState ,
613
- referencedPath : Path ,
614
- seenFileAndExportsOfFile : Set < string > ,
615
- cancellationToken : CancellationToken | undefined ,
616
- computeHash : BuilderState . ComputeHash ,
617
- host : BuilderProgramHost ,
618
- ) : void {
619
- state . referencedMap ! . getKeys ( referencedPath ) ?. forEach ( filePath =>
620
- handleDtsMayChangeOfFileAndExportsOfFile (
621
- state ,
622
- filePath ,
623
- seenFileAndExportsOfFile ,
624
- cancellationToken ,
625
- computeHash ,
626
- host ,
593
+ forEachKeyOfExportedModulesMap ( state , affectedFile . resolvedPath , exportedFromPath =>
594
+ state . referencedMap ! . getKeys ( exportedFromPath ) ?. forEach ( filePath =>
595
+ handleDtsMayChangeOfFileAndExportsOfFile (
596
+ state ,
597
+ filePath ,
598
+ seenFileAndExportsOfFile ,
599
+ cancellationToken ,
600
+ computeHash ,
601
+ host ,
602
+ )
627
603
)
628
604
) ;
629
605
}
630
606
631
607
/**
632
- * fn on file and iterate on anything that exports this file
608
+ * handle dts and semantic diagnostics on file and iterate on anything that exports this file
633
609
*/
634
610
function handleDtsMayChangeOfFileAndExportsOfFile (
635
611
state : BuilderProgramState ,
@@ -643,24 +619,9 @@ namespace ts {
643
619
644
620
handleDtsMayChangeOf ( state , filePath , cancellationToken , computeHash , host ) ;
645
621
Debug . assert ( ! ! state . currentAffectedFilesExportedModulesMap ) ;
646
- // Go through exported modules from cache first
647
- // If exported modules has path, all files referencing file exported from are affected
648
- state . currentAffectedFilesExportedModulesMap . getKeys ( filePath ) ?. forEach ( exportedFromPath =>
649
- handleDtsMayChangeOfFileAndExportsOfFile (
650
- state ,
651
- exportedFromPath ,
652
- seenFileAndExportsOfFile ,
653
- cancellationToken ,
654
- computeHash ,
655
- host ,
656
- )
657
- ) ;
658
622
659
- // If exported from path is not from cache and exported modules has path, all files referencing file exported from are affected
660
- state . exportedModulesMap ! . getKeys ( filePath ) ?. forEach ( exportedFromPath =>
661
- // If the cache had an updated value, skip
662
- ! state . currentAffectedFilesExportedModulesMap ! . hasKey ( exportedFromPath ) &&
663
- ! state . currentAffectedFilesExportedModulesMap ! . deletedKeys ( ) ?. has ( exportedFromPath ) &&
623
+ // If exported modules has path, all files referencing file exported from are affected
624
+ forEachKeyOfExportedModulesMap ( state , filePath , exportedFromPath =>
664
625
handleDtsMayChangeOfFileAndExportsOfFile (
665
626
state ,
666
627
exportedFromPath ,
@@ -684,7 +645,6 @@ namespace ts {
684
645
) ;
685
646
}
686
647
687
-
688
648
/**
689
649
* This is called after completing operation on the next affected file.
690
650
* The operations here are postponed to ensure that cancellation during the iteration is handled correctly
0 commit comments