mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 11:24:49 -05:00
Resolution is valid unless it is invalidated
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user