Skip to content

Commit 5604503

Browse files
committed
More refactoring
1 parent e3f2da0 commit 5604503

File tree

1 file changed

+25
-65
lines changed

1 file changed

+25
-65
lines changed

src/compiler/builder.ts

Lines changed: 25 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,18 @@ namespace ts {
540540
return newSignature !== oldSignature;
541541
}
542542

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+
543555
/**
544556
* Iterate on referencing modules that export entities from affected file and delete diagnostics and add pending emit
545557
*/
@@ -578,58 +590,22 @@ namespace ts {
578590
const seenFileAndExportsOfFile = new Set<string>();
579591
// Go through exported modules from cache first
580592
// 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+
)
627603
)
628604
);
629605
}
630606

631607
/**
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
633609
*/
634610
function handleDtsMayChangeOfFileAndExportsOfFile(
635611
state: BuilderProgramState,
@@ -643,24 +619,9 @@ namespace ts {
643619

644620
handleDtsMayChangeOf(state, filePath, cancellationToken, computeHash, host);
645621
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-
);
658622

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 =>
664625
handleDtsMayChangeOfFileAndExportsOfFile(
665626
state,
666627
exportedFromPath,
@@ -684,7 +645,6 @@ namespace ts {
684645
);
685646
}
686647

687-
688648
/**
689649
* This is called after completing operation on the next affected file.
690650
* The operations here are postponed to ensure that cancellation during the iteration is handled correctly

0 commit comments

Comments
 (0)