Reflect getCurrentProgram as Program|undefined in the ResolutionHostCache

If there were any exceptions, the getCurrentProgram might return undefined so this is defensive check for program
Fixes #25765
This commit is contained in:
Sheetal Nandi
2018-07-20 12:20:39 -07:00
committed by Mine Starks
parent d222c95e3a
commit 07da12167e

View File

@@ -52,7 +52,7 @@ namespace ts {
getGlobalCache?(): string | undefined;
writeLog(s: string): void;
maxNumberOfFilesToIterateForInvalidation?: number;
getCurrentProgram(): Program;
getCurrentProgram(): Program | undefined;
}
interface DirectoryWatchesOfFailedLookup {
@@ -497,7 +497,8 @@ namespace ts {
}
function watchFailedLookupLocationOfNonRelativeModuleResolutions(resolutions: ResolutionWithFailedLookupLocations[], name: string) {
const updateResolution = resolutionHost.getCurrentProgram().getTypeChecker().tryFindAmbientModuleWithoutAugmentations(name) ?
const program = resolutionHost.getCurrentProgram();
const updateResolution = program && program.getTypeChecker().tryFindAmbientModuleWithoutAugmentations(name) ?
setRefCountToUndefined : watchFailedLookupLocationOfResolution;
resolutions.forEach(updateResolution);
}