Skip to content

Commit e4bf58a

Browse files
committed
More refactoring
1 parent c984298 commit e4bf58a

File tree

1 file changed

+25
-65
lines changed

1 file changed

+25
-65
lines changed

Diff for: src/compiler/builder.ts

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

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

634610
/**
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
636612
*/
637613
function handleDtsMayChangeOfFileAndExportsOfFile(
638614
state: BuilderProgramState,
@@ -646,24 +622,9 @@ namespace ts {
646622

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

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 =>
667628
handleDtsMayChangeOfFileAndExportsOfFile(
668629
state,
669630
exportedFromPath,
@@ -687,7 +648,6 @@ namespace ts {
687648
);
688649
}
689650

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

0 commit comments

Comments
 (0)