Skip to content

Commit a8ebf4d

Browse files
sheetalkamattypescript-bot
authored andcommitted
Cherry-pick PR microsoft#39889 into release-4.0
Component commits: c3ac7fa Handle the fact that noResolveResolution resolution is reused Fixes microsoft#39795
1 parent 5463606 commit a8ebf4d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/compiler/resolutionCache.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ namespace ts {
406406
perDirectoryResolution.set(name, resolution);
407407
}
408408
resolutionsInFile.set(name, resolution);
409-
watchFailedLookupLocationsOfExternalModuleResolutions(name, resolution, path, getResolutionWithResolvedFileName);
409+
watchFailedLookupLocationsOfExternalModuleResolutions(name, resolution, path, getResolutionWithResolvedFileName, noResolveResolution);
410410
if (existingResolution) {
411411
stopWatchFailedLookupLocationOfResolution(existingResolution, path, getResolutionWithResolvedFileName);
412412
}
@@ -561,14 +561,15 @@ namespace ts {
561561
resolution: T,
562562
filePath: Path,
563563
getResolutionWithResolvedFileName: GetResolutionWithResolvedFileName<T, R>,
564+
noResolveResolution: T
564565
) {
565566
if (resolution.refCount) {
566567
resolution.refCount++;
567568
Debug.assertDefined(resolution.files);
568569
}
569570
else {
570571
resolution.refCount = 1;
571-
Debug.assert(resolution.files === undefined);
572+
Debug.assert(resolution.files === undefined || (resolution === noResolveResolution && length(noResolveResolution.files) === 0));
572573
if (isExternalModuleNameRelative(name)) {
573574
watchFailedLookupLocationOfResolution(resolution);
574575
}

src/testRunner/unittests/tsserver/approximateSemanticOnlyServer.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,23 @@ function fooB() { }`
213213
assert.isFalse(project.dirty);
214214
checkProjectActualFiles(project, [libFile.path, file1.path, file2.path, file3.path, something.path]);
215215
});
216+
217+
it("should not crash when external module name resolution is reused", () => {
218+
const { session, file1, file2, file3 } = setup();
219+
const service = session.getProjectService();
220+
openFilesForSession([file1], session);
221+
checkNumberOfProjects(service, { inferredProjects: 1 });
222+
const project = service.inferredProjects[0];
223+
checkProjectActualFiles(project, [libFile.path, file1.path, file2.path]);
224+
225+
// Close the file that contains non relative external module name and open some file that doesnt have non relative external module import
226+
closeFilesForSession([file1], session);
227+
openFilesForSession([file3], session);
228+
checkProjectActualFiles(project, [libFile.path, file3.path]);
229+
230+
// Open file with non relative external module name
231+
openFilesForSession([file2], session);
232+
checkProjectActualFiles(project, [libFile.path, file2.path, file3.path]);
233+
});
216234
});
217235
}

0 commit comments

Comments
 (0)