From 0f51bdbb4ff76697d72497a0fc229aaefc7dd4c0 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 14 Sep 2016 06:21:07 -0700 Subject: [PATCH] Rename function and use `directorySeparator` variables --- src/compiler/core.ts | 9 +++++---- src/compiler/program.ts | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index eb90b5f5ec..8c0ca87d86 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -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; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 94f87700d9..ab306e90f3 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -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); }