Skip to content

Commit 5331454

Browse files
dayninMylesBorins
authored andcommittedFeb 21, 2018
path: replace "magic" numbers by readable constants
PR-URL: #18654 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Kyle Farnung <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 92ed071 commit 5331454

File tree

3 files changed

+144
-111
lines changed

3 files changed

+144
-111
lines changed
 

‎lib/internal/constants.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
module.exports = {
4+
// Alphabet chars.
5+
CHAR_UPPERCASE_A: 65, /*A*/
6+
CHAR_LOWERCASE_A: 97, /*a*/
7+
CHAR_UPPERCASE_Z: 90, /*Z*/
8+
CHAR_LOWERCASE_Z: 122, /*z*/
9+
10+
// Non-alphabetic chars.
11+
CHAR_DOT: 46, /*.*/
12+
CHAR_FORWARD_SLASH: 47, /*/*/
13+
CHAR_BACKWARD_SLASH: 92, /*\*/
14+
CHAR_COLON: 58, /*:*/
15+
CHAR_QUESTION_MARK: 63, /*?*/
16+
};

‎lib/path.js

+127-111
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222
'use strict';
2323

2424
const errors = require('internal/errors');
25+
const {
26+
CHAR_UPPERCASE_A,
27+
CHAR_LOWERCASE_A,
28+
CHAR_UPPERCASE_Z,
29+
CHAR_LOWERCASE_Z,
30+
CHAR_DOT,
31+
CHAR_FORWARD_SLASH,
32+
CHAR_BACKWARD_SLASH,
33+
CHAR_COLON,
34+
CHAR_QUESTION_MARK,
35+
} = require('internal/constants');
2536

2637
function assertPath(path) {
2738
if (typeof path !== 'string') {
@@ -39,17 +50,17 @@ function normalizeStringWin32(path, allowAboveRoot) {
3950
for (var i = 0; i <= path.length; ++i) {
4051
if (i < path.length)
4152
code = path.charCodeAt(i);
42-
else if (code === 47/*/*/ || code === 92/*\*/)
53+
else if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
4354
break;
4455
else
45-
code = 47/*/*/;
46-
if (code === 47/*/*/ || code === 92/*\*/) {
56+
code = CHAR_FORWARD_SLASH;
57+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
4758
if (lastSlash === i - 1 || dots === 1) {
4859
// NOOP
4960
} else if (lastSlash !== i - 1 && dots === 2) {
5061
if (res.length < 2 || lastSegmentLength !== 2 ||
51-
res.charCodeAt(res.length - 1) !== 46/*.*/ ||
52-
res.charCodeAt(res.length - 2) !== 46/*.*/) {
62+
res.charCodeAt(res.length - 1) !== CHAR_DOT ||
63+
res.charCodeAt(res.length - 2) !== CHAR_DOT) {
5364
if (res.length > 2) {
5465
const lastSlashIndex = res.lastIndexOf('\\');
5566
if (lastSlashIndex !== res.length - 1) {
@@ -88,7 +99,7 @@ function normalizeStringWin32(path, allowAboveRoot) {
8899
}
89100
lastSlash = i;
90101
dots = 0;
91-
} else if (code === 46/*.*/ && dots !== -1) {
102+
} else if (code === CHAR_DOT && dots !== -1) {
92103
++dots;
93104
} else {
94105
dots = -1;
@@ -107,17 +118,17 @@ function normalizeStringPosix(path, allowAboveRoot) {
107118
for (var i = 0; i <= path.length; ++i) {
108119
if (i < path.length)
109120
code = path.charCodeAt(i);
110-
else if (code === 47/*/*/)
121+
else if (code === CHAR_FORWARD_SLASH)
111122
break;
112123
else
113-
code = 47/*/*/;
114-
if (code === 47/*/*/) {
124+
code = CHAR_FORWARD_SLASH;
125+
if (code === CHAR_FORWARD_SLASH) {
115126
if (lastSlash === i - 1 || dots === 1) {
116127
// NOOP
117128
} else if (lastSlash !== i - 1 && dots === 2) {
118129
if (res.length < 2 || lastSegmentLength !== 2 ||
119-
res.charCodeAt(res.length - 1) !== 46/*.*/ ||
120-
res.charCodeAt(res.length - 2) !== 46/*.*/) {
130+
res.charCodeAt(res.length - 1) !== CHAR_DOT ||
131+
res.charCodeAt(res.length - 2) !== CHAR_DOT) {
121132
if (res.length > 2) {
122133
const lastSlashIndex = res.lastIndexOf('/');
123134
if (lastSlashIndex !== res.length - 1) {
@@ -156,7 +167,7 @@ function normalizeStringPosix(path, allowAboveRoot) {
156167
}
157168
lastSlash = i;
158169
dots = 0;
159-
} else if (code === 46/*.*/ && dots !== -1) {
170+
} else if (code === CHAR_DOT && dots !== -1) {
160171
++dots;
161172
} else {
162173
dots = -1;
@@ -223,22 +234,22 @@ const win32 = {
223234

224235
// Try to match a root
225236
if (len > 1) {
226-
if (code === 47/*/*/ || code === 92/*\*/) {
237+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
227238
// Possible UNC root
228239

229240
// If we started with a separator, we know we at least have an
230241
// absolute path of some kind (UNC or otherwise)
231242
isAbsolute = true;
232243

233244
code = path.charCodeAt(1);
234-
if (code === 47/*/*/ || code === 92/*\*/) {
245+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
235246
// Matched double path separator at beginning
236247
var j = 2;
237248
var last = j;
238249
// Match 1 or more non-path separators
239250
for (; j < len; ++j) {
240251
code = path.charCodeAt(j);
241-
if (code === 47/*/*/ || code === 92/*\*/)
252+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
242253
break;
243254
}
244255
if (j < len && j !== last) {
@@ -248,7 +259,7 @@ const win32 = {
248259
// Match 1 or more path separators
249260
for (; j < len; ++j) {
250261
code = path.charCodeAt(j);
251-
if (code !== 47/*/*/ && code !== 92/*\*/)
262+
if (code !== CHAR_FORWARD_SLASH && code !== CHAR_BACKWARD_SLASH)
252263
break;
253264
}
254265
if (j < len && j !== last) {
@@ -257,7 +268,10 @@ const win32 = {
257268
// Match 1 or more non-path separators
258269
for (; j < len; ++j) {
259270
code = path.charCodeAt(j);
260-
if (code === 47/*/*/ || code === 92/*\*/)
271+
const isPathSeparator =
272+
code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
273+
274+
if (isPathSeparator)
261275
break;
262276
}
263277
if (j === len) {
@@ -276,16 +290,16 @@ const win32 = {
276290
} else {
277291
rootEnd = 1;
278292
}
279-
} else if ((code >= 65/*A*/ && code <= 90/*Z*/) ||
280-
(code >= 97/*a*/ && code <= 122/*z*/)) {
293+
} else if ((code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
294+
(code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z)) {
281295
// Possible device root
282296

283-
if (path.charCodeAt(1) === 58/*:*/) {
297+
if (path.charCodeAt(1) === CHAR_COLON) {
284298
device = path.slice(0, 2);
285299
rootEnd = 2;
286300
if (len > 2) {
287301
code = path.charCodeAt(2);
288-
if (code === 47/*/*/ || code === 92/*\*/) {
302+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
289303
// Treat separator following drive name as an absolute path
290304
// indicator
291305
isAbsolute = true;
@@ -294,7 +308,7 @@ const win32 = {
294308
}
295309
}
296310
}
297-
} else if (code === 47/*/*/ || code === 92/*\*/) {
311+
} else if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
298312
// `path` contains just a path separator
299313
rootEnd = 1;
300314
isAbsolute = true;
@@ -343,22 +357,22 @@ const win32 = {
343357

344358
// Try to match a root
345359
if (len > 1) {
346-
if (code === 47/*/*/ || code === 92/*\*/) {
360+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
347361
// Possible UNC root
348362

349363
// If we started with a separator, we know we at least have an absolute
350364
// path of some kind (UNC or otherwise)
351365
isAbsolute = true;
352366

353367
code = path.charCodeAt(1);
354-
if (code === 47/*/*/ || code === 92/*\*/) {
368+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
355369
// Matched double path separator at beginning
356370
var j = 2;
357371
var last = j;
358372
// Match 1 or more non-path separators
359373
for (; j < len; ++j) {
360374
code = path.charCodeAt(j);
361-
if (code === 47/*/*/ || code === 92/*\*/)
375+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
362376
break;
363377
}
364378
if (j < len && j !== last) {
@@ -368,7 +382,7 @@ const win32 = {
368382
// Match 1 or more path separators
369383
for (; j < len; ++j) {
370384
code = path.charCodeAt(j);
371-
if (code !== 47/*/*/ && code !== 92/*\*/)
385+
if (code !== CHAR_FORWARD_SLASH && code !== CHAR_BACKWARD_SLASH)
372386
break;
373387
}
374388
if (j < len && j !== last) {
@@ -377,7 +391,7 @@ const win32 = {
377391
// Match 1 or more non-path separators
378392
for (; j < len; ++j) {
379393
code = path.charCodeAt(j);
380-
if (code === 47/*/*/ || code === 92/*\*/)
394+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
381395
break;
382396
}
383397
if (j === len) {
@@ -397,16 +411,16 @@ const win32 = {
397411
} else {
398412
rootEnd = 1;
399413
}
400-
} else if ((code >= 65/*A*/ && code <= 90/*Z*/) ||
401-
(code >= 97/*a*/ && code <= 122/*z*/)) {
414+
} else if ((code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
415+
(code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z)) {
402416
// Possible device root
403417

404-
if (path.charCodeAt(1) === 58/*:*/) {
418+
if (path.charCodeAt(1) === CHAR_COLON) {
405419
device = path.slice(0, 2);
406420
rootEnd = 2;
407421
if (len > 2) {
408422
code = path.charCodeAt(2);
409-
if (code === 47/*/*/ || code === 92/*\*/) {
423+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
410424
// Treat separator following drive name as an absolute path
411425
// indicator
412426
isAbsolute = true;
@@ -415,14 +429,15 @@ const win32 = {
415429
}
416430
}
417431
}
418-
} else if (code === 47/*/*/ || code === 92/*\*/) {
432+
} else if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
419433
// `path` contains just a path separator, exit early to avoid unnecessary
420434
// work
421435
return '\\';
422436
}
423437

424438
code = path.charCodeAt(len - 1);
425-
var trailingSeparator = (code === 47/*/*/ || code === 92/*\*/);
439+
var trailingSeparator =
440+
(code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH);
426441
var tail;
427442
if (rootEnd < len)
428443
tail = normalizeStringWin32(path.slice(rootEnd), !isAbsolute);
@@ -462,15 +477,15 @@ const win32 = {
462477
if (len === 0)
463478
return false;
464479
var code = path.charCodeAt(0);
465-
if (code === 47/*/*/ || code === 92/*\*/) {
480+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
466481
return true;
467-
} else if ((code >= 65/*A*/ && code <= 90/*Z*/) ||
468-
(code >= 97/*a*/ && code <= 122/*z*/)) {
482+
} else if ((code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
483+
(code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z)) {
469484
// Possible device root
470485

471-
if (len > 2 && path.charCodeAt(1) === 58/*:*/) {
486+
if (len > 2 && path.charCodeAt(1) === CHAR_COLON) {
472487
code = path.charCodeAt(2);
473-
if (code === 47/*/*/ || code === 92/*\*/)
488+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
474489
return true;
475490
}
476491
}
@@ -514,16 +529,16 @@ const win32 = {
514529
var needsReplace = true;
515530
var slashCount = 0;
516531
var code = firstPart.charCodeAt(0);
517-
if (code === 47/*/*/ || code === 92/*\*/) {
532+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
518533
++slashCount;
519534
const firstLen = firstPart.length;
520535
if (firstLen > 1) {
521536
code = firstPart.charCodeAt(1);
522-
if (code === 47/*/*/ || code === 92/*\*/) {
537+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
523538
++slashCount;
524539
if (firstLen > 2) {
525540
code = firstPart.charCodeAt(2);
526-
if (code === 47/*/*/ || code === 92/*\*/)
541+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
527542
++slashCount;
528543
else {
529544
// We matched a UNC path in the first part
@@ -537,7 +552,7 @@ const win32 = {
537552
// Find any more consecutive slashes we need to replace
538553
for (; slashCount < joined.length; ++slashCount) {
539554
code = joined.charCodeAt(slashCount);
540-
if (code !== 47/*/*/ && code !== 92/*\*/)
555+
if (code !== CHAR_FORWARD_SLASH && code !== CHAR_BACKWARD_SLASH)
541556
break;
542557
}
543558

@@ -576,27 +591,27 @@ const win32 = {
576591
// Trim any leading backslashes
577592
var fromStart = 0;
578593
for (; fromStart < from.length; ++fromStart) {
579-
if (from.charCodeAt(fromStart) !== 92/*\*/)
594+
if (from.charCodeAt(fromStart) !== CHAR_BACKWARD_SLASH)
580595
break;
581596
}
582597
// Trim trailing backslashes (applicable to UNC paths only)
583598
var fromEnd = from.length;
584599
for (; fromEnd - 1 > fromStart; --fromEnd) {
585-
if (from.charCodeAt(fromEnd - 1) !== 92/*\*/)
600+
if (from.charCodeAt(fromEnd - 1) !== CHAR_BACKWARD_SLASH)
586601
break;
587602
}
588603
var fromLen = (fromEnd - fromStart);
589604

590605
// Trim any leading backslashes
591606
var toStart = 0;
592607
for (; toStart < to.length; ++toStart) {
593-
if (to.charCodeAt(toStart) !== 92/*\*/)
608+
if (to.charCodeAt(toStart) !== CHAR_BACKWARD_SLASH)
594609
break;
595610
}
596611
// Trim trailing backslashes (applicable to UNC paths only)
597612
var toEnd = to.length;
598613
for (; toEnd - 1 > toStart; --toEnd) {
599-
if (to.charCodeAt(toEnd - 1) !== 92/*\*/)
614+
if (to.charCodeAt(toEnd - 1) !== CHAR_BACKWARD_SLASH)
600615
break;
601616
}
602617
var toLen = (toEnd - toStart);
@@ -608,7 +623,7 @@ const win32 = {
608623
for (; i <= length; ++i) {
609624
if (i === length) {
610625
if (toLen > length) {
611-
if (to.charCodeAt(toStart + i) === 92/*\*/) {
626+
if (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) {
612627
// We get here if `from` is the exact base path for `to`.
613628
// For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
614629
return toOrig.slice(toStart + i + 1);
@@ -619,7 +634,7 @@ const win32 = {
619634
}
620635
}
621636
if (fromLen > length) {
622-
if (from.charCodeAt(fromStart + i) === 92/*\*/) {
637+
if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) {
623638
// We get here if `to` is the exact base path for `from`.
624639
// For example: from='C:\\foo\\bar'; to='C:\\foo'
625640
lastCommonSep = i;
@@ -635,7 +650,7 @@ const win32 = {
635650
var toCode = to.charCodeAt(toStart + i);
636651
if (fromCode !== toCode)
637652
break;
638-
else if (fromCode === 92/*\*/)
653+
else if (fromCode === CHAR_BACKWARD_SLASH)
639654
lastCommonSep = i;
640655
}
641656

@@ -651,7 +666,7 @@ const win32 = {
651666
// Generate the relative path based on the path difference between `to` and
652667
// `from`
653668
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
654-
if (i === fromEnd || from.charCodeAt(i) === 92/*\*/) {
669+
if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) {
655670
if (out.length === 0)
656671
out += '..';
657672
else
@@ -665,7 +680,7 @@ const win32 = {
665680
return out + toOrig.slice(toStart + lastCommonSep, toEnd);
666681
else {
667682
toStart += lastCommonSep;
668-
if (toOrig.charCodeAt(toStart) === 92/*\*/)
683+
if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH)
669684
++toStart;
670685
return toOrig.slice(toStart, toEnd);
671686
}
@@ -685,22 +700,22 @@ const win32 = {
685700

686701
if (resolvedPath.length >= 3) {
687702
var code = resolvedPath.charCodeAt(0);
688-
if (code === 92/*\*/) {
703+
if (code === CHAR_BACKWARD_SLASH) {
689704
// Possible UNC root
690705

691-
if (resolvedPath.charCodeAt(1) === 92/*\*/) {
706+
if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) {
692707
code = resolvedPath.charCodeAt(2);
693-
if (code !== 63/*?*/ && code !== 46/*.*/) {
708+
if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) {
694709
// Matched non-long UNC root, convert the path to a long UNC path
695710
return '\\\\?\\UNC\\' + resolvedPath.slice(2);
696711
}
697712
}
698-
} else if ((code >= 65/*A*/ && code <= 90/*Z*/) ||
699-
(code >= 97/*a*/ && code <= 122/*z*/)) {
713+
} else if ((code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
714+
(code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z)) {
700715
// Possible device root
701716

702-
if (resolvedPath.charCodeAt(1) === 58/*:*/ &&
703-
resolvedPath.charCodeAt(2) === 92/*\*/) {
717+
if (resolvedPath.charCodeAt(1) === CHAR_COLON &&
718+
resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) {
704719
// Matched device root, convert the path to a long UNC path
705720
return '\\\\?\\' + resolvedPath;
706721
}
@@ -723,20 +738,20 @@ const win32 = {
723738

724739
// Try to match a root
725740
if (len > 1) {
726-
if (code === 47/*/*/ || code === 92/*\*/) {
741+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
727742
// Possible UNC root
728743

729744
rootEnd = offset = 1;
730745

731746
code = path.charCodeAt(1);
732-
if (code === 47/*/*/ || code === 92/*\*/) {
747+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
733748
// Matched double path separator at beginning
734749
var j = 2;
735750
var last = j;
736751
// Match 1 or more non-path separators
737752
for (; j < len; ++j) {
738753
code = path.charCodeAt(j);
739-
if (code === 47/*/*/ || code === 92/*\*/)
754+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
740755
break;
741756
}
742757
if (j < len && j !== last) {
@@ -745,7 +760,7 @@ const win32 = {
745760
// Match 1 or more path separators
746761
for (; j < len; ++j) {
747762
code = path.charCodeAt(j);
748-
if (code !== 47/*/*/ && code !== 92/*\*/)
763+
if (code !== CHAR_FORWARD_SLASH && code !== CHAR_BACKWARD_SLASH)
749764
break;
750765
}
751766
if (j < len && j !== last) {
@@ -754,7 +769,7 @@ const win32 = {
754769
// Match 1 or more non-path separators
755770
for (; j < len; ++j) {
756771
code = path.charCodeAt(j);
757-
if (code === 47/*/*/ || code === 92/*\*/)
772+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
758773
break;
759774
}
760775
if (j === len) {
@@ -771,28 +786,28 @@ const win32 = {
771786
}
772787
}
773788
}
774-
} else if ((code >= 65/*A*/ && code <= 90/*Z*/) ||
775-
(code >= 97/*a*/ && code <= 122/*z*/)) {
789+
} else if ((code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
790+
(code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z)) {
776791
// Possible device root
777792

778-
if (path.charCodeAt(1) === 58/*:*/) {
793+
if (path.charCodeAt(1) === CHAR_COLON) {
779794
rootEnd = offset = 2;
780795
if (len > 2) {
781796
code = path.charCodeAt(2);
782-
if (code === 47/*/*/ || code === 92/*\*/)
797+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
783798
rootEnd = offset = 3;
784799
}
785800
}
786801
}
787-
} else if (code === 47/*/*/ || code === 92/*\*/) {
802+
} else if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
788803
// `path` contains just a path separator, exit early to avoid
789804
// unnecessary work
790805
return path;
791806
}
792807

793808
for (var i = len - 1; i >= offset; --i) {
794809
code = path.charCodeAt(i);
795-
if (code === 47/*/*/ || code === 92/*\*/) {
810+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
796811
if (!matchedSlash) {
797812
end = i;
798813
break;
@@ -827,9 +842,9 @@ const win32 = {
827842
// disregarded
828843
if (path.length >= 2) {
829844
const drive = path.charCodeAt(0);
830-
if ((drive >= 65/*A*/ && drive <= 90/*Z*/) ||
831-
(drive >= 97/*a*/ && drive <= 122/*z*/)) {
832-
if (path.charCodeAt(1) === 58/*:*/)
845+
if ((drive >= CHAR_UPPERCASE_A && drive <= CHAR_UPPERCASE_Z) ||
846+
(drive >= CHAR_LOWERCASE_A && drive <= CHAR_LOWERCASE_Z)) {
847+
if (path.charCodeAt(1) === CHAR_COLON)
833848
start = 2;
834849
}
835850
}
@@ -841,7 +856,7 @@ const win32 = {
841856
var firstNonSlashEnd = -1;
842857
for (i = path.length - 1; i >= start; --i) {
843858
const code = path.charCodeAt(i);
844-
if (code === 47/*/*/ || code === 92/*\*/) {
859+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
845860
// If we reached a path separator that was not part of a set of path
846861
// separators at the end of the string, stop now
847862
if (!matchedSlash) {
@@ -881,7 +896,7 @@ const win32 = {
881896
} else {
882897
for (i = path.length - 1; i >= start; --i) {
883898
const code = path.charCodeAt(i);
884-
if (code === 47/*/*/ || code === 92/*\*/) {
899+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
885900
// If we reached a path separator that was not part of a set of path
886901
// separators at the end of the string, stop now
887902
if (!matchedSlash) {
@@ -919,16 +934,16 @@ const win32 = {
919934
// disregarded
920935
if (path.length >= 2) {
921936
const code = path.charCodeAt(0);
922-
if (path.charCodeAt(1) === 58/*:*/ &&
923-
((code >= 65/*A*/ && code <= 90/*Z*/) ||
924-
(code >= 97/*a*/ && code <= 122/*z*/))) {
937+
if (path.charCodeAt(1) === CHAR_COLON &&
938+
((code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
939+
(code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z))) {
925940
start = startPart = 2;
926941
}
927942
}
928943

929944
for (var i = path.length - 1; i >= start; --i) {
930945
const code = path.charCodeAt(i);
931-
if (code === 47/*/*/ || code === 92/*\*/) {
946+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
932947
// If we reached a path separator that was not part of a set of path
933948
// separators at the end of the string, stop now
934949
if (!matchedSlash) {
@@ -943,7 +958,7 @@ const win32 = {
943958
matchedSlash = false;
944959
end = i + 1;
945960
}
946-
if (code === 46/*.*/) {
961+
if (code === CHAR_DOT) {
947962
// If this is our first dot, mark it as the start of our extension
948963
if (startDot === -1)
949964
startDot = i;
@@ -992,19 +1007,19 @@ const win32 = {
9921007

9931008
// Try to match a root
9941009
if (len > 1) {
995-
if (code === 47/*/*/ || code === 92/*\*/) {
1010+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
9961011
// Possible UNC root
9971012

9981013
code = path.charCodeAt(1);
9991014
rootEnd = 1;
1000-
if (code === 47/*/*/ || code === 92/*\*/) {
1015+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
10011016
// Matched double path separator at beginning
10021017
var j = 2;
10031018
var last = j;
10041019
// Match 1 or more non-path separators
10051020
for (; j < len; ++j) {
10061021
code = path.charCodeAt(j);
1007-
if (code === 47/*/*/ || code === 92/*\*/)
1022+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
10081023
break;
10091024
}
10101025
if (j < len && j !== last) {
@@ -1013,7 +1028,7 @@ const win32 = {
10131028
// Match 1 or more path separators
10141029
for (; j < len; ++j) {
10151030
code = path.charCodeAt(j);
1016-
if (code !== 47/*/*/ && code !== 92/*\*/)
1031+
if (code !== CHAR_FORWARD_SLASH && code !== CHAR_BACKWARD_SLASH)
10171032
break;
10181033
}
10191034
if (j < len && j !== last) {
@@ -1022,7 +1037,7 @@ const win32 = {
10221037
// Match 1 or more non-path separators
10231038
for (; j < len; ++j) {
10241039
code = path.charCodeAt(j);
1025-
if (code === 47/*/*/ || code === 92/*\*/)
1040+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
10261041
break;
10271042
}
10281043
if (j === len) {
@@ -1037,15 +1052,15 @@ const win32 = {
10371052
}
10381053
}
10391054
}
1040-
} else if ((code >= 65/*A*/ && code <= 90/*Z*/) ||
1041-
(code >= 97/*a*/ && code <= 122/*z*/)) {
1055+
} else if ((code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
1056+
(code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z)) {
10421057
// Possible device root
10431058

1044-
if (path.charCodeAt(1) === 58/*:*/) {
1059+
if (path.charCodeAt(1) === CHAR_COLON) {
10451060
rootEnd = 2;
10461061
if (len > 2) {
10471062
code = path.charCodeAt(2);
1048-
if (code === 47/*/*/ || code === 92/*\*/) {
1063+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
10491064
if (len === 3) {
10501065
// `path` contains just a drive root, exit early to avoid
10511066
// unnecessary work
@@ -1062,7 +1077,7 @@ const win32 = {
10621077
}
10631078
}
10641079
}
1065-
} else if (code === 47/*/*/ || code === 92/*\*/) {
1080+
} else if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
10661081
// `path` contains just a path separator, exit early to avoid
10671082
// unnecessary work
10681083
ret.root = ret.dir = path;
@@ -1085,7 +1100,7 @@ const win32 = {
10851100
// Get non-dir info
10861101
for (; i >= rootEnd; --i) {
10871102
code = path.charCodeAt(i);
1088-
if (code === 47/*/*/ || code === 92/*\*/) {
1103+
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
10891104
// If we reached a path separator that was not part of a set of path
10901105
// separators at the end of the string, stop now
10911106
if (!matchedSlash) {
@@ -1100,7 +1115,7 @@ const win32 = {
11001115
matchedSlash = false;
11011116
end = i + 1;
11021117
}
1103-
if (code === 46/*.*/) {
1118+
if (code === CHAR_DOT) {
11041119
// If this is our first dot, mark it as the start of our extension
11051120
if (startDot === -1)
11061121
startDot = i;
@@ -1174,7 +1189,7 @@ const posix = {
11741189
}
11751190

11761191
resolvedPath = path + '/' + resolvedPath;
1177-
resolvedAbsolute = path.charCodeAt(0) === 47/*/*/;
1192+
resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
11781193
}
11791194

11801195
// At this point the path should be resolved to a full absolute path, but
@@ -1202,8 +1217,9 @@ const posix = {
12021217
if (path.length === 0)
12031218
return '.';
12041219

1205-
const isAbsolute = path.charCodeAt(0) === 47/*/*/;
1206-
const trailingSeparator = path.charCodeAt(path.length - 1) === 47/*/*/;
1220+
const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1221+
const trailingSeparator =
1222+
path.charCodeAt(path.length - 1) === CHAR_FORWARD_SLASH;
12071223

12081224
// Normalize the path
12091225
path = normalizeStringPosix(path, !isAbsolute);
@@ -1221,7 +1237,7 @@ const posix = {
12211237

12221238
isAbsolute: function isAbsolute(path) {
12231239
assertPath(path);
1224-
return path.length > 0 && path.charCodeAt(0) === 47/*/*/;
1240+
return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH;
12251241
},
12261242

12271243

@@ -1261,7 +1277,7 @@ const posix = {
12611277
// Trim any leading backslashes
12621278
var fromStart = 1;
12631279
for (; fromStart < from.length; ++fromStart) {
1264-
if (from.charCodeAt(fromStart) !== 47/*/*/)
1280+
if (from.charCodeAt(fromStart) !== CHAR_FORWARD_SLASH)
12651281
break;
12661282
}
12671283
var fromEnd = from.length;
@@ -1270,7 +1286,7 @@ const posix = {
12701286
// Trim any leading backslashes
12711287
var toStart = 1;
12721288
for (; toStart < to.length; ++toStart) {
1273-
if (to.charCodeAt(toStart) !== 47/*/*/)
1289+
if (to.charCodeAt(toStart) !== CHAR_FORWARD_SLASH)
12741290
break;
12751291
}
12761292
var toEnd = to.length;
@@ -1283,7 +1299,7 @@ const posix = {
12831299
for (; i <= length; ++i) {
12841300
if (i === length) {
12851301
if (toLen > length) {
1286-
if (to.charCodeAt(toStart + i) === 47/*/*/) {
1302+
if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) {
12871303
// We get here if `from` is the exact base path for `to`.
12881304
// For example: from='/foo/bar'; to='/foo/bar/baz'
12891305
return to.slice(toStart + i + 1);
@@ -1293,7 +1309,7 @@ const posix = {
12931309
return to.slice(toStart + i);
12941310
}
12951311
} else if (fromLen > length) {
1296-
if (from.charCodeAt(fromStart + i) === 47/*/*/) {
1312+
if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
12971313
// We get here if `to` is the exact base path for `from`.
12981314
// For example: from='/foo/bar/baz'; to='/foo/bar'
12991315
lastCommonSep = i;
@@ -1309,15 +1325,15 @@ const posix = {
13091325
var toCode = to.charCodeAt(toStart + i);
13101326
if (fromCode !== toCode)
13111327
break;
1312-
else if (fromCode === 47/*/*/)
1328+
else if (fromCode === CHAR_FORWARD_SLASH)
13131329
lastCommonSep = i;
13141330
}
13151331

13161332
var out = '';
13171333
// Generate the relative path based on the path difference between `to`
13181334
// and `from`
13191335
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
1320-
if (i === fromEnd || from.charCodeAt(i) === 47/*/*/) {
1336+
if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) {
13211337
if (out.length === 0)
13221338
out += '..';
13231339
else
@@ -1331,7 +1347,7 @@ const posix = {
13311347
return out + to.slice(toStart + lastCommonSep);
13321348
else {
13331349
toStart += lastCommonSep;
1334-
if (to.charCodeAt(toStart) === 47/*/*/)
1350+
if (to.charCodeAt(toStart) === CHAR_FORWARD_SLASH)
13351351
++toStart;
13361352
return to.slice(toStart);
13371353
}
@@ -1348,12 +1364,12 @@ const posix = {
13481364
if (path.length === 0)
13491365
return '.';
13501366
var code = path.charCodeAt(0);
1351-
var hasRoot = (code === 47/*/*/);
1367+
var hasRoot = (code === CHAR_FORWARD_SLASH);
13521368
var end = -1;
13531369
var matchedSlash = true;
13541370
for (var i = path.length - 1; i >= 1; --i) {
13551371
code = path.charCodeAt(i);
1356-
if (code === 47/*/*/) {
1372+
if (code === CHAR_FORWARD_SLASH) {
13571373
if (!matchedSlash) {
13581374
end = i;
13591375
break;
@@ -1389,7 +1405,7 @@ const posix = {
13891405
var firstNonSlashEnd = -1;
13901406
for (i = path.length - 1; i >= 0; --i) {
13911407
const code = path.charCodeAt(i);
1392-
if (code === 47/*/*/) {
1408+
if (code === CHAR_FORWARD_SLASH) {
13931409
// If we reached a path separator that was not part of a set of path
13941410
// separators at the end of the string, stop now
13951411
if (!matchedSlash) {
@@ -1428,7 +1444,7 @@ const posix = {
14281444
return path.slice(start, end);
14291445
} else {
14301446
for (i = path.length - 1; i >= 0; --i) {
1431-
if (path.charCodeAt(i) === 47/*/*/) {
1447+
if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
14321448
// If we reached a path separator that was not part of a set of path
14331449
// separators at the end of the string, stop now
14341450
if (!matchedSlash) {
@@ -1461,7 +1477,7 @@ const posix = {
14611477
var preDotState = 0;
14621478
for (var i = path.length - 1; i >= 0; --i) {
14631479
const code = path.charCodeAt(i);
1464-
if (code === 47/*/*/) {
1480+
if (code === CHAR_FORWARD_SLASH) {
14651481
// If we reached a path separator that was not part of a set of path
14661482
// separators at the end of the string, stop now
14671483
if (!matchedSlash) {
@@ -1476,7 +1492,7 @@ const posix = {
14761492
matchedSlash = false;
14771493
end = i + 1;
14781494
}
1479-
if (code === 46/*.*/) {
1495+
if (code === CHAR_DOT) {
14801496
// If this is our first dot, mark it as the start of our extension
14811497
if (startDot === -1)
14821498
startDot = i;
@@ -1519,7 +1535,7 @@ const posix = {
15191535
if (path.length === 0)
15201536
return ret;
15211537
var code = path.charCodeAt(0);
1522-
var isAbsolute = (code === 47/*/*/);
1538+
var isAbsolute = (code === CHAR_FORWARD_SLASH);
15231539
var start;
15241540
if (isAbsolute) {
15251541
ret.root = '/';
@@ -1540,7 +1556,7 @@ const posix = {
15401556
// Get non-dir info
15411557
for (; i >= start; --i) {
15421558
code = path.charCodeAt(i);
1543-
if (code === 47/*/*/) {
1559+
if (code === CHAR_FORWARD_SLASH) {
15441560
// If we reached a path separator that was not part of a set of path
15451561
// separators at the end of the string, stop now
15461562
if (!matchedSlash) {
@@ -1555,7 +1571,7 @@ const posix = {
15551571
matchedSlash = false;
15561572
end = i + 1;
15571573
}
1558-
if (code === 46/*.*/) {
1574+
if (code === CHAR_DOT) {
15591575
// If this is our first dot, mark it as the start of our extension
15601576
if (startDot === -1)
15611577
startDot = i;

‎node.gyp

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
'lib/internal/crypto/random.js',
9797
'lib/internal/crypto/sig.js',
9898
'lib/internal/crypto/util.js',
99+
'lib/internal/constants.js',
99100
'lib/internal/encoding.js',
100101
'lib/internal/errors.js',
101102
'lib/internal/freelist.js',

0 commit comments

Comments
 (0)
Please sign in to comment.