Skip to content

Commit 54f64a1

Browse files
committed
Resolution is valid unless it is invalidated
1 parent 7b2bab5 commit 54f64a1

File tree

7 files changed

+188
-271
lines changed

7 files changed

+188
-271
lines changed

Jakefile.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ var harnessSources = harnessCoreSources.concat([
121121
"transpile.ts",
122122
"reuseProgramStructure.ts",
123123
"textStorage.ts",
124-
"cachingInServerLSHost.ts",
125124
"moduleResolution.ts",
126125
"tsconfigParsing.ts",
127126
"commandLineParsing.ts",

src/compiler/moduleNameResolver.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,21 +1127,4 @@ namespace ts {
11271127
function toSearchResult<T>(value: T | undefined): SearchResult<T> {
11281128
return value !== undefined ? { value } : undefined;
11291129
}
1130-
1131-
/** Calls `callback` on `directory` and every ancestor directory it has, returning the first defined result. */
1132-
function forEachAncestorDirectory<T>(directory: string, callback: (directory: string) => SearchResult<T>): SearchResult<T> {
1133-
while (true) {
1134-
const result = callback(directory);
1135-
if (result !== undefined) {
1136-
return result;
1137-
}
1138-
1139-
const parentPath = getDirectoryPath(directory);
1140-
if (parentPath === directory) {
1141-
return undefined;
1142-
}
1143-
1144-
directory = parentPath;
1145-
}
1146-
}
11471130
}

src/compiler/resolutionCache.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ namespace ts {
184184

185185
const seenNamesInFile = createMap<true>();
186186
for (const name of names) {
187-
// check if this is a duplicate entry in the list
188187
let resolution = resolutionsInFile.get(name);
189-
if (!moduleResolutionIsValid(resolution, name)) {
188+
// Resolution is valid if it is present and not invalidated
189+
if (!resolution || resolution.isInvalidated) {
190190
const existingResolution = resolution;
191191
const resolutionInDirectory = perDirectoryResolution.get(name);
192192
if (resolutionInDirectory) {
@@ -221,25 +221,6 @@ namespace ts {
221221

222222
return resolvedModules;
223223

224-
function moduleResolutionIsValid(resolution: T, name: string): boolean {
225-
// This is already calculated resolution in this round of synchronization
226-
if (seenNamesInFile.has(name)) {
227-
return true;
228-
}
229-
230-
if (!resolution || resolution.isInvalidated) {
231-
return false;
232-
}
233-
234-
const result = getResult(resolution);
235-
if (result) {
236-
return true;
237-
}
238-
// consider situation if we have no candidate locations as valid resolution.
239-
// after all there is no point to invalidate it if we have no idea where to look for the module.
240-
return resolution.failedLookupLocations.length === 0;
241-
}
242-
243224
function resolutionIsEqualTo(oldResolution: T, newResolution: T): boolean {
244225
if (oldResolution === newResolution) {
245226
return true;

src/compiler/utilities.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3609,6 +3609,23 @@ namespace ts {
36093609
export function closeFileWatcherOf<T extends { watcher: FileWatcher; }>(objWithWatcher: T) {
36103610
objWithWatcher.watcher.close();
36113611
}
3612+
3613+
/** Calls `callback` on `directory` and every ancestor directory it has, returning the first defined result. */
3614+
export function forEachAncestorDirectory<T>(directory: string, callback: (directory: string) => T): T {
3615+
while (true) {
3616+
const result = callback(directory);
3617+
if (result !== undefined) {
3618+
return result;
3619+
}
3620+
3621+
const parentPath = getDirectoryPath(directory);
3622+
if (parentPath === directory) {
3623+
return undefined;
3624+
}
3625+
3626+
directory = parentPath;
3627+
}
3628+
}
36123629
}
36133630

36143631
namespace ts {

src/harness/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@
109109
"./unittests/convertToBase64.ts",
110110
"./unittests/transpile.ts",
111111
"./unittests/reuseProgramStructure.ts",
112-
"./unittests/cachingInServerLSHost.ts",
113112
"./unittests/moduleResolution.ts",
114113
"./unittests/tsconfigParsing.ts",
115114
"./unittests/commandLineParsing.ts",

src/harness/unittests/cachingInServerLSHost.ts

Lines changed: 0 additions & 203 deletions
This file was deleted.

0 commit comments

Comments
 (0)