@@ -190,7 +190,6 @@ const win32 = {
190
190
let resolvedDevice = '' ;
191
191
let resolvedTail = '' ;
192
192
let resolvedAbsolute = false ;
193
- let slashCheck = false ;
194
193
195
194
for ( let i = args . length - 1 ; i >= - 1 ; i -- ) {
196
195
let path ;
@@ -222,10 +221,6 @@ const win32 = {
222
221
}
223
222
}
224
223
225
- if ( i === args . length - 1 &&
226
- isPathSeparator ( StringPrototypeCharCodeAt ( path , path . length - 1 ) ) ) {
227
- slashCheck = true ;
228
- }
229
224
const len = path . length ;
230
225
let rootEnd = 0 ;
231
226
let device = '' ;
@@ -273,16 +268,10 @@ const win32 = {
273
268
j ++ ;
274
269
}
275
270
if ( j === len || j !== last ) {
276
- if ( firstPart !== '.' && firstPart !== '?' ) {
277
- // We matched a UNC root
278
- device =
279
- `\\\\${ firstPart } \\${ StringPrototypeSlice ( path , last , j ) } ` ;
280
- rootEnd = j ;
281
- } else {
282
- // We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0)
283
- device = `\\\\${ firstPart } ` ;
284
- rootEnd = 4 ;
285
- }
271
+ // We matched a UNC root
272
+ device =
273
+ `\\\\${ firstPart } \\${ StringPrototypeSlice ( path , last , j ) } ` ;
274
+ rootEnd = j ;
286
275
}
287
276
}
288
277
}
@@ -334,21 +323,9 @@ const win32 = {
334
323
resolvedTail = normalizeString ( resolvedTail , ! resolvedAbsolute , '\\' ,
335
324
isPathSeparator ) ;
336
325
337
- if ( ! resolvedAbsolute ) {
338
- return `${ resolvedDevice } ${ resolvedTail } ` || '.' ;
339
- }
340
-
341
- if ( resolvedTail . length === 0 ) {
342
- return slashCheck ? `${ resolvedDevice } \\` : resolvedDevice ;
343
- }
344
-
345
- if ( slashCheck ) {
346
- return resolvedTail === '\\' ?
347
- `${ resolvedDevice } \\` :
348
- `${ resolvedDevice } \\${ resolvedTail } \\` ;
349
- }
350
-
351
- return `${ resolvedDevice } \\${ resolvedTail } ` ;
326
+ return resolvedAbsolute ?
327
+ `${ resolvedDevice } \\${ resolvedTail } ` :
328
+ `${ resolvedDevice } ${ resolvedTail } ` || '.' ;
352
329
} ,
353
330
354
331
/**
@@ -404,22 +381,17 @@ const win32 = {
404
381
! isPathSeparator ( StringPrototypeCharCodeAt ( path , j ) ) ) {
405
382
j ++ ;
406
383
}
407
- if ( j === len || j !== last ) {
408
- if ( firstPart === '.' || firstPart === '?' ) {
409
- // We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0)
410
- device = `\\\\${ firstPart } ` ;
411
- rootEnd = 4 ;
412
- } else if ( j === len ) {
413
- // We matched a UNC root only
414
- // Return the normalized version of the UNC root since there
415
- // is nothing left to process
416
- return `\\\\${ firstPart } \\${ StringPrototypeSlice ( path , last ) } \\` ;
417
- } else {
418
- // We matched a UNC root with leftovers
419
- device =
420
- `\\\\${ firstPart } \\${ StringPrototypeSlice ( path , last , j ) } ` ;
421
- rootEnd = j ;
422
- }
384
+ if ( j === len ) {
385
+ // We matched a UNC root only
386
+ // Return the normalized version of the UNC root since there
387
+ // is nothing left to process
388
+ return `\\\\${ firstPart } \\${ StringPrototypeSlice ( path , last ) } \\` ;
389
+ }
390
+ if ( j !== last ) {
391
+ // We matched a UNC root with leftovers
392
+ device =
393
+ `\\\\${ firstPart } \\${ StringPrototypeSlice ( path , last , j ) } ` ;
394
+ rootEnd = j ;
423
395
}
424
396
}
425
397
}
@@ -1190,7 +1162,6 @@ const posix = {
1190
1162
resolve ( ...args ) {
1191
1163
let resolvedPath = '' ;
1192
1164
let resolvedAbsolute = false ;
1193
- let slashCheck = false ;
1194
1165
1195
1166
for ( let i = args . length - 1 ; i >= 0 && ! resolvedAbsolute ; i -- ) {
1196
1167
const path = args [ i ] ;
@@ -1200,17 +1171,8 @@ const posix = {
1200
1171
if ( path . length === 0 ) {
1201
1172
continue ;
1202
1173
}
1203
- if ( i === args . length - 1 &&
1204
- isPosixPathSeparator ( StringPrototypeCharCodeAt ( path ,
1205
- path . length - 1 ) ) ) {
1206
- slashCheck = true ;
1207
- }
1208
1174
1209
- if ( resolvedPath . length !== 0 ) {
1210
- resolvedPath = `${ path } /${ resolvedPath } ` ;
1211
- } else {
1212
- resolvedPath = path ;
1213
- }
1175
+ resolvedPath = `${ path } /${ resolvedPath } ` ;
1214
1176
resolvedAbsolute =
1215
1177
StringPrototypeCharCodeAt ( path , 0 ) === CHAR_FORWARD_SLASH ;
1216
1178
}
@@ -1229,20 +1191,10 @@ const posix = {
1229
1191
resolvedPath = normalizeString ( resolvedPath , ! resolvedAbsolute , '/' ,
1230
1192
isPosixPathSeparator ) ;
1231
1193
1232
- if ( ! resolvedAbsolute ) {
1233
- if ( resolvedPath . length === 0 ) {
1234
- return '.' ;
1235
- }
1236
- if ( slashCheck ) {
1237
- return `${ resolvedPath } /` ;
1238
- }
1239
- return resolvedPath ;
1240
- }
1241
-
1242
- if ( resolvedPath . length === 0 || resolvedPath === '/' ) {
1243
- return '/' ;
1194
+ if ( resolvedAbsolute ) {
1195
+ return `/${ resolvedPath } ` ;
1244
1196
}
1245
- return slashCheck ? `/ ${ resolvedPath } /` : `/ ${ resolvedPath } ` ;
1197
+ return resolvedPath . length > 0 ? resolvedPath : '.' ;
1246
1198
} ,
1247
1199
1248
1200
/**
@@ -1326,35 +1278,11 @@ const posix = {
1326
1278
if ( from === to )
1327
1279
return '' ;
1328
1280
1329
- // Trim any leading slashes
1330
- let fromStart = 0 ;
1331
- while ( fromStart < from . length &&
1332
- StringPrototypeCharCodeAt ( from , fromStart ) === CHAR_FORWARD_SLASH ) {
1333
- fromStart ++ ;
1334
- }
1335
- // Trim trailing slashes
1336
- let fromEnd = from . length ;
1337
- while (
1338
- fromEnd - 1 > fromStart &&
1339
- StringPrototypeCharCodeAt ( from , fromEnd - 1 ) === CHAR_FORWARD_SLASH
1340
- ) {
1341
- fromEnd -- ;
1342
- }
1281
+ const fromStart = 1 ;
1282
+ const fromEnd = from . length ;
1343
1283
const fromLen = fromEnd - fromStart ;
1344
-
1345
- // Trim any leading slashes
1346
- let toStart = 0 ;
1347
- while ( toStart < to . length &&
1348
- StringPrototypeCharCodeAt ( to , toStart ) === CHAR_FORWARD_SLASH ) {
1349
- toStart ++ ;
1350
- }
1351
- // Trim trailing slashes
1352
- let toEnd = to . length ;
1353
- while ( toEnd - 1 > toStart &&
1354
- StringPrototypeCharCodeAt ( to , toEnd - 1 ) === CHAR_FORWARD_SLASH ) {
1355
- toEnd -- ;
1356
- }
1357
- const toLen = toEnd - toStart ;
1284
+ const toStart = 1 ;
1285
+ const toLen = to . length - toStart ;
1358
1286
1359
1287
// Compare paths to find the longest common path from root
1360
1288
const length = ( fromLen < toLen ? fromLen : toLen ) ;
0 commit comments