An import ending in "/" is always an import of a directory.

This commit is contained in:
Andy Hanson
2016-08-23 13:38:39 -07:00
parent ddb5a00410
commit 0b71f5f661
9 changed files with 52 additions and 38 deletions

View File

@@ -829,8 +829,20 @@ namespace ts {
export function normalizePath(path: string): string {
path = normalizeSlashes(path);
const rootLength = getRootLength(path);
const root = path.substr(0, rootLength);
const normalized = getNormalizedParts(path, rootLength);
return path.substr(0, rootLength) + normalized.join(directorySeparator);
if (normalized.length) {
const joinedParts = root + normalized.join(directorySeparator);
return isPathToDirectory(path) ? joinedParts + "/" : joinedParts;
}
else {
return root;
}
}
/** A path ending with '/' refers to a directory only, never a file. */
export function isPathToDirectory(path: string): boolean {
return path.charCodeAt(path.length - 1) === CharacterCodes.slash;
}
export function getDirectoryPath(path: Path): Path;

View File

@@ -646,7 +646,7 @@ namespace ts {
trace(state.host, Diagnostics.Loading_module_as_file_Slash_folder_candidate_module_location_0, candidate);
}
const resolvedFileName = loadModuleFromFile(candidate, supportedExtensions, failedLookupLocations, onlyRecordFailures, state);
const resolvedFileName = !isPathToDirectory(candidate) && loadModuleFromFile(candidate, supportedExtensions, failedLookupLocations, onlyRecordFailures, state);
return resolvedFileName || loadNodeModuleFromDirectory(supportedExtensions, candidate, failedLookupLocations, onlyRecordFailures, state);
}