Skip to content

Commit cb26366

Browse files
committed
When user provided resolution is used, invalidate resolutions for all files
In this case there is no way to tell if resolution has changed so resolution cache wont have answers
1 parent 2611c9b commit cb26366

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/compiler/resolutionCache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace ts {
1414

1515
invalidateResolutionOfFile(filePath: Path): void;
1616
removeResolutionsOfFile(filePath: Path): void;
17-
createHasInvalidatedResolution(): HasInvalidatedResolution;
17+
createHasInvalidatedResolution(forceAllFilesAsInvalidated?: boolean): HasInvalidatedResolution;
1818

1919
startCachingPerDirectoryResolution(): void;
2020
finishCachingPerDirectoryResolution(): void;
@@ -159,8 +159,8 @@ namespace ts {
159159
return collected;
160160
}
161161

162-
function createHasInvalidatedResolution(): HasInvalidatedResolution {
163-
if (allFilesHaveInvalidatedResolution) {
162+
function createHasInvalidatedResolution(forceAllFilesAsInvalidated?: boolean): HasInvalidatedResolution {
163+
if (allFilesHaveInvalidatedResolution || forceAllFilesAsInvalidated) {
164164
// Any file asked would have invalidated resolution
165165
filesWithInvalidatedResolutions = undefined;
166166
return returnTrue;

src/compiler/watch.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ namespace ts {
302302

303303
/** If provided, used to resolve the module names, otherwise typescript's default module resolution */
304304
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames?: string[]): ResolvedModule[];
305+
/** If provided, used to resolve type reference directives, otherwise typescript's default resolution */
306+
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string): ResolvedTypeReferenceDirective[];
305307

306308
/** Used to watch changes in source files, missing files needed to update the program or config file */
307309
watchFile(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher;
@@ -520,7 +522,10 @@ namespace ts {
520522
compilerHost.resolveModuleNames = host.resolveModuleNames ?
521523
((moduleNames, containingFile, reusedNames) => host.resolveModuleNames(moduleNames, containingFile, reusedNames)) :
522524
((moduleNames, containingFile, reusedNames) => resolutionCache.resolveModuleNames(moduleNames, containingFile, reusedNames));
523-
compilerHost.resolveTypeReferenceDirectives = resolutionCache.resolveTypeReferenceDirectives.bind(resolutionCache);
525+
compilerHost.resolveTypeReferenceDirectives = host.resolveTypeReferenceDirectives ?
526+
((typeDirectiveNames, containingFile) => host.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile)) :
527+
((typeDirectiveNames, containingFile) => resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile));
528+
const userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
524529

525530
reportWatchDiagnostic(Diagnostics.Starting_compilation_in_watch_mode);
526531
synchronizeProgram();
@@ -542,7 +547,8 @@ namespace ts {
542547
}
543548
}
544549

545-
const hasInvalidatedResolution = resolutionCache.createHasInvalidatedResolution();
550+
// All resolutions are invalid if user provided resolutions
551+
const hasInvalidatedResolution = resolutionCache.createHasInvalidatedResolution(userProvidedResolution);
546552
if (isProgramUptoDate(program, rootFileNames, compilerOptions, getSourceVersion, fileExists, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames)) {
547553
return program;
548554
}

tests/baselines/reference/api/typescript.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3894,6 +3894,8 @@ declare namespace ts {
38943894
trace?(s: string): void;
38953895
/** If provided, used to resolve the module names, otherwise typescript's default module resolution */
38963896
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames?: string[]): ResolvedModule[];
3897+
/** If provided, used to resolve type reference directives, otherwise typescript's default resolution */
3898+
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string): ResolvedTypeReferenceDirective[];
38973899
/** Used to watch changes in source files, missing files needed to update the program or config file */
38983900
watchFile(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher;
38993901
/** Used to watch resolved module's failed lookup locations, config file specs, type roots where auto type reference directives are added */

0 commit comments

Comments
 (0)