mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 20:37:46 -05:00
Kick out of normalizePath if there's nothing to do (#44173)
* Kick out of normalizePath if there's nothing to do ...using `relativePathSegmentRegExp`. Bonus: use a regex to handle "/./" to avoid splitting and joining in a common case. When building the compiler, for example, it looks like ~95% of arguments to `normalizePath` do not require any normalization. * Check normalization before and after . cleanup * Also cleanup leading ./
This commit is contained in:
@@ -552,6 +552,19 @@ namespace ts {
|
||||
|
||||
export function normalizePath(path: string): string {
|
||||
path = normalizeSlashes(path);
|
||||
// Most paths don't require normalization
|
||||
if (!relativePathSegmentRegExp.test(path)) {
|
||||
return path;
|
||||
}
|
||||
// Some paths only require cleanup of `/./` or leading `./`
|
||||
const simplified = path.replace(/\/\.\//g, "/").replace(/^\.\//, "");
|
||||
if (simplified !== path) {
|
||||
path = simplified;
|
||||
if (!relativePathSegmentRegExp.test(path)) {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
// Other paths require full normalization
|
||||
const normalized = getPathFromPathComponents(reducePathComponents(getPathComponents(path)));
|
||||
return normalized && hasTrailingDirectorySeparator(path) ? ensureTrailingDirectorySeparator(normalized) : normalized;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user