Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 50177b1

Browse filesBrowse files
authored
Merge pull request #9396 from zhengbli/fix9186
Check getCurrentDirectory availability in getEffectiveTypeRoots
2 parents ec02077 + d5cad23 commit 50177b1
Copy full SHA for 50177b1

File tree

Expand file treeCollapse file tree

2 files changed

+31
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+31
-6
lines changed

‎src/compiler/program.ts

Copy file name to clipboardExpand all lines: src/compiler/program.ts
+22-6Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,22 @@ namespace ts {
187187
const typeReferenceExtensions = [".d.ts"];
188188

189189
function getEffectiveTypeRoots(options: CompilerOptions, host: ModuleResolutionHost) {
190-
return options.typeRoots ||
191-
map(defaultTypeRoots, d => combinePaths(options.configFilePath ? getDirectoryPath(options.configFilePath) : host.getCurrentDirectory(), d));
190+
if (options.typeRoots) {
191+
return options.typeRoots;
192+
}
193+
194+
let currentDirectory: string;
195+
if (options.configFilePath) {
196+
currentDirectory = getDirectoryPath(options.configFilePath);
197+
}
198+
else if (host.getCurrentDirectory) {
199+
currentDirectory = host.getCurrentDirectory();
200+
}
201+
202+
if (!currentDirectory) {
203+
return undefined;
204+
}
205+
return map(defaultTypeRoots, d => combinePaths(currentDirectory, d));
192206
}
193207

194208
/**
@@ -228,7 +242,7 @@ namespace ts {
228242
const failedLookupLocations: string[] = [];
229243

230244
// Check primary library paths
231-
if (typeRoots.length) {
245+
if (typeRoots && typeRoots.length) {
232246
if (traceEnabled) {
233247
trace(host, Diagnostics.Resolving_with_primary_search_path_0, typeRoots.join(", "));
234248
}
@@ -1046,9 +1060,11 @@ namespace ts {
10461060
let result: string[] = [];
10471061
if (host.directoryExists && host.getDirectories) {
10481062
const typeRoots = getEffectiveTypeRoots(options, host);
1049-
for (const root of typeRoots) {
1050-
if (host.directoryExists(root)) {
1051-
result = result.concat(host.getDirectories(root));
1063+
if (typeRoots) {
1064+
for (const root of typeRoots) {
1065+
if (host.directoryExists(root)) {
1066+
result = result.concat(host.getDirectories(root));
1067+
}
10521068
}
10531069
}
10541070
}
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path='../fourslash.ts' />
2+
3+
/////// <reference types="foo" />
4+
////var x: number;
5+
////x./*1*/
6+
7+
goTo.marker("1");
8+
verify.not.completionListIsEmpty();
9+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.