Simplify normalizeSlashes (#50154)

This commit is contained in:
Jake Bailey 2022-08-10 14:20:00 -04:00 committed by GitHub
parent 5fbf3b04dc
commit 7f1dc78f54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -452,12 +452,9 @@ namespace ts {
* Normalize path separators, converting `\` into `/`.
*/
export function normalizeSlashes(path: string): string {
const index = path.indexOf("\\");
if (index === -1) {
return path;
}
backslashRegExp.lastIndex = index; // prime regex with known position
return path.replace(backslashRegExp, directorySeparator);
return path.indexOf("\\") !== -1
? path.replace(backslashRegExp, directorySeparator)
: path;
}
/**