Fix for crash for auto import completions with a rooted rootDirs entry (#47411)

* Add failing test case.

* Guard against undefined relative path.
This commit is contained in:
Daniel Rosenwasser
2022-01-12 13:45:06 -08:00
committed by GitHub
parent 14f33d5c4b
commit 461fb65623
2 changed files with 26 additions and 2 deletions

View File

@@ -854,8 +854,8 @@ namespace ts.moduleSpecifiers {
function getPathRelativeToRootDirs(path: string, rootDirs: readonly string[], getCanonicalFileName: GetCanonicalFileName): string | undefined {
return firstDefined(rootDirs, rootDir => {
const relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName)!; // TODO: GH#18217
return isPathRelativeToParent(relativePath) ? undefined : relativePath;
const relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName);
return relativePath !== undefined && isPathRelativeToParent(relativePath) ? undefined : relativePath;
});
}