Rename function and use directorySeparator variables

This commit is contained in:
Andy Hanson 2016-09-14 06:21:07 -07:00
parent 48c67cbdb5
commit 0f51bdbb4f
2 changed files with 6 additions and 5 deletions

View file

@ -1018,7 +1018,8 @@ namespace ts {
return 0;
}
export let directorySeparator = "/";
export const directorySeparator = "/";
const directorySeparatorCharCode = CharacterCodes.slash;
function getNormalizedParts(normalizedSlashedPath: string, rootLength: number) {
const parts = normalizedSlashedPath.substr(rootLength).split(directorySeparator);
const normalized: string[] = [];
@ -1047,7 +1048,7 @@ namespace ts {
const normalized = getNormalizedParts(path, rootLength);
if (normalized.length) {
const joinedParts = root + normalized.join(directorySeparator);
return isPathToDirectory(path) ? joinedParts + "/" : joinedParts;
return pathEndsWithDirectorySeparator(path) ? joinedParts + directorySeparator : joinedParts;
}
else {
return root;
@ -1055,8 +1056,8 @@ namespace ts {
}
/** 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 pathEndsWithDirectorySeparator(path: string): boolean {
return path.charCodeAt(path.length - 1) === directorySeparatorCharCode;
}
export function getDirectoryPath(path: Path): Path;

View file

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