Skip to content

Commit 461fb65

Browse files
Fix for crash for auto import completions with a rooted rootDirs entry (#47411)
* Add failing test case. * Guard against undefined relative path.
1 parent 14f33d5 commit 461fb65

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/compiler/moduleSpecifiers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,8 @@ namespace ts.moduleSpecifiers {
854854

855855
function getPathRelativeToRootDirs(path: string, rootDirs: readonly string[], getCanonicalFileName: GetCanonicalFileName): string | undefined {
856856
return firstDefined(rootDirs, rootDir => {
857-
const relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName)!; // TODO: GH#18217
858-
return isPathRelativeToParent(relativePath) ? undefined : relativePath;
857+
const relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName);
858+
return relativePath !== undefined && isPathRelativeToParent(relativePath) ? undefined : relativePath;
859859
});
860860
}
861861

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference path="./fourslash.ts" />
2+
3+
// @Filename: /dir/foo.ts
4+
//// export function foo() {}
5+
6+
// @Filename: /dir/bar.ts
7+
//// /*$*/
8+
9+
// @Filename: /dir/tsconfig.json
10+
////{
11+
//// "compilerOptions": {
12+
//// "module": "amd",
13+
//// "moduleResolution": "classic",
14+
//// "rootDirs": ["D:/"]
15+
//// }
16+
////}
17+
18+
goTo.marker("$");
19+
verify.completions({
20+
preferences: {
21+
includeCompletionsForModuleExports: true,
22+
allowIncompleteCompletions: true,
23+
}
24+
});

0 commit comments

Comments
 (0)