Skip to content

Commit c670444

Browse files
committed
Make getFilesByName buildinfo ready
1 parent 82977c2 commit c670444

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

src/compiler/program.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ namespace ts {
824824
* - false if sourceFile missing for source of project reference redirect
825825
* - undefined otherwise
826826
*/
827-
const filesByName = new Map<string, SourceFile | false | undefined>();
827+
const filesByName = new Map<string, SourceFile | false | 0>();
828828
let missingFilePaths: readonly Path[] | undefined;
829829
// stores 'filename -> file association' ignoring case
830830
// used to track cases when two file names differ only in casing
@@ -921,7 +921,7 @@ namespace ts {
921921
}
922922
}
923923

924-
missingFilePaths = arrayFrom(mapDefinedIterator(filesByName.entries(), ([path, file]) => file === undefined ? path as Path : undefined));
924+
missingFilePaths = arrayFrom(mapDefinedIterator(filesByName.entries(), ([path, file]) => file === 0 ? path as Path : undefined));
925925
files = stableSort(processingDefaultLibFiles, compareDefaultLibFiles).concat(processingOtherFiles);
926926
processingDefaultLibFiles = undefined;
927927
processingOtherFiles = undefined;
@@ -1568,7 +1568,7 @@ namespace ts {
15681568
}
15691569
return;
15701570
}
1571-
filesByName.set(path, filesByName.get(oldFile.path));
1571+
filesByName.set(path, filesByName.get(oldFile.path)!);
15721572
});
15731573

15741574
files = newSourceFiles;
@@ -1658,8 +1658,8 @@ namespace ts {
16581658
(_ref, index) => resolvedProjectReferences![index]?.commandLine,
16591659
fileName => {
16601660
const path = toPath(fileName);
1661-
const sourceFile = getSourceFileByPath(path);
1662-
return sourceFile ? sourceFile.text : filesByName.has(path) ? undefined : host.readFile(path);
1661+
const sourceFile = filesByName.get(path);
1662+
return sourceFile ? sourceFile.text : sourceFile !== undefined ? undefined : host.readFile(path);
16631663
}
16641664
);
16651665
}
@@ -2484,13 +2484,13 @@ namespace ts {
24842484
}
24852485
}
24862486
const originalFileName = fileName;
2487-
if (filesByName.has(path)) {
2488-
const file = filesByName.get(path);
2489-
addFileToRefFileMap(fileName, file || undefined, refFile);
2487+
const cachedFile = filesByName.get(path);
2488+
if (cachedFile !== undefined) {
2489+
addFileToRefFileMap(fileName, cachedFile || undefined, refFile);
24902490
// try to check if we've already seen this file but with a different casing in path
24912491
// NOTE: this only makes sense for case-insensitive file systems, and only on files which are not redirected
2492-
if (file && options.forceConsistentCasingInFileNames) {
2493-
const checkedName = file.fileName;
2492+
if (cachedFile && options.forceConsistentCasingInFileNames) {
2493+
const checkedName = cachedFile.fileName;
24942494
const isRedirect = toPath(checkedName) !== toPath(fileName);
24952495
if (isRedirect) {
24962496
fileName = getProjectReferenceRedirect(fileName) || fileName;
@@ -2499,34 +2499,34 @@ namespace ts {
24992499
const checkedAbsolutePath = getNormalizedAbsolutePathWithoutRoot(checkedName, currentDirectory);
25002500
const inputAbsolutePath = getNormalizedAbsolutePathWithoutRoot(fileName, currentDirectory);
25012501
if (checkedAbsolutePath !== inputAbsolutePath) {
2502-
reportFileNamesDifferOnlyInCasingError(fileName, file, refFile);
2502+
reportFileNamesDifferOnlyInCasingError(fileName, cachedFile, refFile);
25032503
}
25042504
}
25052505

25062506
// If the file was previously found via a node_modules search, but is now being processed as a root file,
25072507
// then everything it sucks in may also be marked incorrectly, and needs to be checked again.
2508-
if (file && sourceFilesFoundSearchingNodeModules.get(file.path) && currentNodeModulesDepth === 0) {
2509-
sourceFilesFoundSearchingNodeModules.set(file.path, false);
2508+
if (cachedFile && sourceFilesFoundSearchingNodeModules.get(cachedFile.path) && currentNodeModulesDepth === 0) {
2509+
sourceFilesFoundSearchingNodeModules.set(cachedFile.path, false);
25102510
if (!options.noResolve) {
2511-
processReferencedFiles(file, isDefaultLib);
2512-
processTypeReferenceDirectives(file);
2511+
processReferencedFiles(cachedFile, isDefaultLib);
2512+
processTypeReferenceDirectives(cachedFile);
25132513
}
25142514
if (!options.noLib) {
2515-
processLibReferenceDirectives(file);
2515+
processLibReferenceDirectives(cachedFile);
25162516
}
25172517

2518-
modulesWithElidedImports.set(file.path, false);
2519-
processImportedModules(file);
2518+
modulesWithElidedImports.set(cachedFile.path, false);
2519+
processImportedModules(cachedFile);
25202520
}
25212521
// See if we need to reprocess the imports due to prior skipped imports
2522-
else if (file && modulesWithElidedImports.get(file.path)) {
2522+
else if (cachedFile && modulesWithElidedImports.get(cachedFile.path)) {
25232523
if (currentNodeModulesDepth < maxNodeModuleJsDepth) {
2524-
modulesWithElidedImports.set(file.path, false);
2525-
processImportedModules(file);
2524+
modulesWithElidedImports.set(cachedFile.path, false);
2525+
processImportedModules(cachedFile);
25262526
}
25272527
}
25282528

2529-
return file || undefined;
2529+
return cachedFile || undefined;
25302530
}
25312531

25322532
let redirectedPath: Path | undefined;
@@ -2639,11 +2639,11 @@ namespace ts {
26392639

26402640
function addFileToFilesByName(file: SourceFile | undefined, path: Path, redirectedPath: Path | undefined) {
26412641
if (redirectedPath) {
2642-
filesByName.set(redirectedPath, file);
2642+
filesByName.set(redirectedPath, file || 0);
26432643
filesByName.set(path, file || false);
26442644
}
26452645
else {
2646-
filesByName.set(path, file);
2646+
filesByName.set(path, file || 0);
26472647
}
26482648
}
26492649

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3717,7 +3717,7 @@ namespace ts {
37173717
/* @internal */
37183718
getRefFileMap(): MultiMap<Path, RefFile> | undefined;
37193719
/* @internal */
3720-
getFilesByNameMap(): ESMap<string, SourceFile | false | undefined>;
3720+
getFilesByNameMap(): ESMap<string, SourceFile | false | 0>;
37213721

37223722
/**
37233723
* Emits the JavaScript and declaration files. If targetSourceFile is not specified, then

0 commit comments

Comments
 (0)