Skip to content

Commit 63a8cb6

Browse files
committed
use Map instead of Array
1 parent ea0c7eb commit 63a8cb6

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/compiler/program.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ namespace ts {
594594
let diagnosticsProducingTypeChecker: TypeChecker;
595595
let noDiagnosticsTypeChecker: TypeChecker;
596596
let classifiableNames: UnderscoreEscapedMap<true>;
597-
let unmodifiedSourceFilesWithAmbientModules: SourceFile[] | undefined;
597+
const ambientModuleNameToUnmodifiedFileName = createMap<string>();
598598

599599
const cachedSemanticDiagnosticsForFile: DiagnosticCache<Diagnostic> = {};
600600
const cachedDeclarationDiagnosticsForFile: DiagnosticCache<DiagnosticWithLocation> = {};
@@ -1006,16 +1006,14 @@ namespace ts {
10061006
}
10071007

10081008
// at least one of declarations should come from non-modified source file
1009-
const firstUnmodifiedFile = unmodifiedSourceFilesWithAmbientModules && unmodifiedSourceFilesWithAmbientModules.find(
1010-
f => contains(f.ambientModuleNames, moduleName)
1011-
);
1009+
const unmodifiedFile = ambientModuleNameToUnmodifiedFileName.get(moduleName);
10121010

1013-
if (!firstUnmodifiedFile) {
1011+
if (!unmodifiedFile) {
10141012
return false;
10151013
}
10161014

10171015
if (isTraceEnabled(options, host)) {
1018-
trace(host, Diagnostics.Module_0_was_resolved_as_ambient_module_declared_in_1_since_this_file_was_not_modified, moduleName, firstUnmodifiedFile.fileName);
1016+
trace(host, Diagnostics.Module_0_was_resolved_as_ambient_module_declared_in_1_since_this_file_was_not_modified, moduleName, unmodifiedFile);
10191017
}
10201018
return true;
10211019
}
@@ -1204,7 +1202,13 @@ namespace ts {
12041202
}
12051203

12061204
const modifiedFiles = modifiedSourceFiles.map(f => f.oldFile);
1207-
unmodifiedSourceFilesWithAmbientModules = oldSourceFiles.filter((f) => !!f.ambientModuleNames.length && !contains(modifiedFiles, f));
1205+
for (const oldFile of oldSourceFiles) {
1206+
if (!contains(modifiedFiles, oldFile)) {
1207+
for (const moduleName of oldFile.ambientModuleNames) {
1208+
ambientModuleNameToUnmodifiedFileName.set(moduleName, oldFile.fileName);
1209+
}
1210+
}
1211+
}
12081212
// try to verify results of module resolution
12091213
for (const { oldFile: oldSourceFile, newFile: newSourceFile } of modifiedSourceFiles) {
12101214
const newSourceFilePath = getNormalizedAbsolutePath(newSourceFile.originalFileName, currentDirectory);

0 commit comments

Comments
 (0)