Skip to content

Commit 8d41f0b

Browse files
committed
More refactoring
1 parent 1f0d800 commit 8d41f0b

File tree

1 file changed

+25
-65
lines changed

1 file changed

+25
-65
lines changed

src/compiler/builder.ts

+25-65
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,18 @@ namespace ts {
542542
return newSignature !== oldSignature;
543543
}
544544

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+
545557
/**
546558
* Iterate on referencing modules that export entities from affected file and delete diagnostics and add pending emit
547559
*/
@@ -580,58 +592,22 @@ namespace ts {
580592
const seenFileAndExportsOfFile = new Set<string>();
581593
// Go through exported modules from cache first
582594
// 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+
)
629605
)
630606
);
631607
}
632608

633609
/**
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
635611
*/
636612
function handleDtsMayChangeOfFileAndExportsOfFile(
637613
state: BuilderProgramState,
@@ -645,24 +621,9 @@ namespace ts {
645621

646622
handleDtsMayChangeOf(state, filePath, cancellationToken, computeHash, host);
647623
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-
);
660624

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 =>
666627
handleDtsMayChangeOfFileAndExportsOfFile(
667628
state,
668629
exportedFromPath,
@@ -686,7 +647,6 @@ namespace ts {
686647
);
687648
}
688649

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

0 commit comments

Comments
 (0)