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