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