Skip to content

Commit 0f51bdb

Browse files
author
Andy Hanson
committed
Rename function and use directorySeparator variables
1 parent 48c67cb commit 0f51bdb

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/compiler/core.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,8 @@ namespace ts {
10181018
return 0;
10191019
}
10201020

1021-
export let directorySeparator = "/";
1021+
export const directorySeparator = "/";
1022+
const directorySeparatorCharCode = CharacterCodes.slash;
10221023
function getNormalizedParts(normalizedSlashedPath: string, rootLength: number) {
10231024
const parts = normalizedSlashedPath.substr(rootLength).split(directorySeparator);
10241025
const normalized: string[] = [];
@@ -1047,16 +1048,16 @@ namespace ts {
10471048
const normalized = getNormalizedParts(path, rootLength);
10481049
if (normalized.length) {
10491050
const joinedParts = root + normalized.join(directorySeparator);
1050-
return isPathToDirectory(path) ? joinedParts + "/" : joinedParts;
1051+
return pathEndsWithDirectorySeparator(path) ? joinedParts + directorySeparator : joinedParts;
10511052
}
10521053
else {
10531054
return root;
10541055
}
10551056
}
10561057

10571058
/** A path ending with '/' refers to a directory only, never a file. */
1058-
export function isPathToDirectory(path: string): boolean {
1059-
return path.charCodeAt(path.length - 1) === CharacterCodes.slash;
1059+
export function pathEndsWithDirectorySeparator(path: string): boolean {
1060+
return path.charCodeAt(path.length - 1) === directorySeparatorCharCode;
10601061
}
10611062

10621063
export function getDirectoryPath(path: Path): Path;

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ namespace ts {
670670
trace(state.host, Diagnostics.Loading_module_as_file_Slash_folder_candidate_module_location_0, candidate);
671671
}
672672

673-
const resolvedFileName = !isPathToDirectory(candidate) && loadModuleFromFile(candidate, supportedExtensions, failedLookupLocations, onlyRecordFailures, state);
673+
const resolvedFileName = !pathEndsWithDirectorySeparator(candidate) && loadModuleFromFile(candidate, supportedExtensions, failedLookupLocations, onlyRecordFailures, state);
674674

675675
return resolvedFileName || loadNodeModuleFromDirectory(supportedExtensions, candidate, failedLookupLocations, onlyRecordFailures, state);
676676
}

0 commit comments

Comments
 (0)