File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ namespace ts {
88 export const directorySeparator = "/" ;
99 export const altDirectorySeparator = "\\" ;
1010 const urlSchemeSeparator = "://" ;
11- const backslashRegExp = / \\ / g;
1211
1312 //// Path Tests
1413
@@ -452,7 +451,20 @@ namespace ts {
452451 * Normalize path separators, converting `\` into `/`.
453452 */
454453 export function normalizeSlashes ( path : string ) : string {
455- return path . replace ( backslashRegExp , directorySeparator ) ;
454+ let lastSliceStart = 0 ;
455+ let segments : string [ ] | undefined ;
456+ for ( let i = 0 ; i < path . length ; i ++ ) {
457+ const c = path . charCodeAt ( i ) ;
458+ if ( c === CharacterCodes . backslash ) {
459+ ( segments ||= [ ] ) . push ( path . slice ( lastSliceStart , i ) ) ;
460+ lastSliceStart = i + 1 ;
461+ }
462+ }
463+ if ( segments ) {
464+ segments . push ( path . slice ( lastSliceStart ) ) ;
465+ return segments . join ( directorySeparator ) ;
466+ }
467+ return path ;
456468 }
457469
458470 /**
You can’t perform that action at this time.
0 commit comments