Skip to content

Commit bcccae2

Browse files
authored
Handle the fact that noResolveResolution resolution is reused (microsoft#39889)
Fixes microsoft#39795
1 parent 6247364 commit bcccae2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Diff for: src/compiler/resolutionCache.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ namespace ts {
568568
}
569569
else {
570570
resolution.refCount = 1;
571-
Debug.assert(resolution.files === undefined);
571+
Debug.assert(length(resolution.files) === 0); // This resolution shouldnt be referenced by any file yet
572572
if (isExternalModuleNameRelative(name)) {
573573
watchFailedLookupLocationOfResolution(resolution);
574574
}

Diff for: src/testRunner/unittests/tsserver/approximateSemanticOnlyServer.ts

+18
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)