Resolution is valid unless it is invalidated

This commit is contained in:
Sheetal Nandi
2017-09-05 17:36:19 -07:00
parent 7b2bab5b86
commit 54f64a1695
7 changed files with 188 additions and 271 deletions

View File

@@ -1127,21 +1127,4 @@ namespace ts {
function toSearchResult<T>(value: T | undefined): SearchResult<T> {
return value !== undefined ? { value } : undefined;
}
/** Calls `callback` on `directory` and every ancestor directory it has, returning the first defined result. */
function forEachAncestorDirectory<T>(directory: string, callback: (directory: string) => SearchResult<T>): SearchResult<T> {
while (true) {
const result = callback(directory);
if (result !== undefined) {
return result;
}
const parentPath = getDirectoryPath(directory);
if (parentPath === directory) {
return undefined;
}
directory = parentPath;
}
}
}

View File

@@ -184,9 +184,9 @@ namespace ts {
const seenNamesInFile = createMap<true>();
for (const name of names) {
// check if this is a duplicate entry in the list
let resolution = resolutionsInFile.get(name);
if (!moduleResolutionIsValid(resolution, name)) {
// Resolution is valid if it is present and not invalidated
if (!resolution || resolution.isInvalidated) {
const existingResolution = resolution;
const resolutionInDirectory = perDirectoryResolution.get(name);
if (resolutionInDirectory) {
@@ -221,25 +221,6 @@ namespace ts {
return resolvedModules;
function moduleResolutionIsValid(resolution: T, name: string): boolean {
// This is already calculated resolution in this round of synchronization
if (seenNamesInFile.has(name)) {
return true;
}
if (!resolution || resolution.isInvalidated) {
return false;
}
const result = getResult(resolution);
if (result) {
return true;
}
// consider situation if we have no candidate locations as valid resolution.
// after all there is no point to invalidate it if we have no idea where to look for the module.
return resolution.failedLookupLocations.length === 0;
}
function resolutionIsEqualTo(oldResolution: T, newResolution: T): boolean {
if (oldResolution === newResolution) {
return true;

View File

@@ -3609,6 +3609,23 @@ namespace ts {
export function closeFileWatcherOf<T extends { watcher: FileWatcher; }>(objWithWatcher: T) {
objWithWatcher.watcher.close();
}
/** Calls `callback` on `directory` and every ancestor directory it has, returning the first defined result. */
export function forEachAncestorDirectory<T>(directory: string, callback: (directory: string) => T): T {
while (true) {
const result = callback(directory);
if (result !== undefined) {
return result;
}
const parentPath = getDirectoryPath(directory);
if (parentPath === directory) {
return undefined;
}
directory = parentPath;
}
}
}
namespace ts {