@@ -47,6 +47,19 @@ module.exports = Module;
47
47
const internalESModule = require ( 'internal/process/modules' ) ;
48
48
const ModuleJob = require ( 'internal/loader/ModuleJob' ) ;
49
49
const createDynamicModule = require ( 'internal/loader/CreateDynamicModule' ) ;
50
+ const {
51
+ CHAR_UPPERCASE_A ,
52
+ CHAR_LOWERCASE_A ,
53
+ CHAR_UPPERCASE_Z ,
54
+ CHAR_LOWERCASE_Z ,
55
+ CHAR_FORWARD_SLASH ,
56
+ CHAR_BACKWARD_SLASH ,
57
+ CHAR_COLON ,
58
+ CHAR_DOT ,
59
+ CHAR_UNDERSCORE ,
60
+ CHAR_0 ,
61
+ CHAR_9 ,
62
+ } = require ( 'internal/constants' ) ;
50
63
51
64
function stat ( filename ) {
52
65
filename = path . toNamespacedPath ( filename ) ;
@@ -201,7 +214,7 @@ Module._findPath = function(request, paths, isMain) {
201
214
202
215
var exts ;
203
216
var trailingSlash = request . length > 0 &&
204
- request . charCodeAt ( request . length - 1 ) === 47 /*/*/ ;
217
+ request . charCodeAt ( request . length - 1 ) === CHAR_FORWARD_SLASH ;
205
218
206
219
// For each path
207
220
for ( var i = 0 ; i < paths . length ; i ++ ) {
@@ -276,8 +289,8 @@ if (process.platform === 'win32') {
276
289
277
290
// return root node_modules when path is 'D:\\'.
278
291
// path.resolve will make sure from.length >=3 in Windows.
279
- if ( from . charCodeAt ( from . length - 1 ) === 92 /*\*/ &&
280
- from . charCodeAt ( from . length - 2 ) === 58 /*:*/ )
292
+ if ( from . charCodeAt ( from . length - 1 ) === CHAR_BACKWARD_SLASH &&
293
+ from . charCodeAt ( from . length - 2 ) === CHAR_COLON )
281
294
return [ from + 'node_modules' ] ;
282
295
283
296
const paths = [ ] ;
@@ -290,7 +303,9 @@ if (process.platform === 'win32') {
290
303
// Use colon as an extra condition since we can get node_modules
291
304
// path for drive root like 'C:\node_modules' and don't need to
292
305
// parse drive name.
293
- if ( code === 92 /*\*/ || code === 47 /*/*/ || code === 58 /*:*/ ) {
306
+ if ( code === CHAR_BACKWARD_SLASH ||
307
+ code === CHAR_FORWARD_SLASH ||
308
+ code === CHAR_COLON ) {
294
309
if ( p !== nmLen )
295
310
paths . push ( from . slice ( 0 , last ) + '\\node_modules' ) ;
296
311
last = i ;
@@ -324,7 +339,7 @@ if (process.platform === 'win32') {
324
339
var last = from . length ;
325
340
for ( var i = from . length - 1 ; i >= 0 ; -- i ) {
326
341
const code = from . charCodeAt ( i ) ;
327
- if ( code === 47 /*/*/ ) {
342
+ if ( code === CHAR_FORWARD_SLASH ) {
328
343
if ( p !== nmLen )
329
344
paths . push ( from . slice ( 0 , last ) + '/node_modules' ) ;
330
345
last = i ;
@@ -357,9 +372,9 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
357
372
358
373
// Check for relative path
359
374
if ( request . length < 2 ||
360
- request . charCodeAt ( 0 ) !== 46 /*.*/ ||
361
- ( request . charCodeAt ( 1 ) !== 46 /*.*/ &&
362
- request . charCodeAt ( 1 ) !== 47 /*/*/ ) ) {
375
+ request . charCodeAt ( 0 ) !== CHAR_DOT ||
376
+ ( request . charCodeAt ( 1 ) !== CHAR_DOT &&
377
+ request . charCodeAt ( 1 ) !== CHAR_FORWARD_SLASH ) ) {
363
378
var paths = modulePaths ;
364
379
if ( parent ) {
365
380
if ( ! parent . paths )
@@ -407,10 +422,10 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
407
422
// We matched 'index.', let's validate the rest
408
423
for ( ; i < base . length ; ++ i ) {
409
424
const code = base . charCodeAt ( i ) ;
410
- if ( code !== 95 /*_*/ &&
411
- ( code < 48 /*0*/ || code > 57 /*9*/ ) &&
412
- ( code < 65 /*A*/ || code > 90 /*Z*/ ) &&
413
- ( code < 97 /*a*/ || code > 122 /*z*/ ) )
425
+ if ( code !== CHAR_UNDERSCORE &&
426
+ ( code < CHAR_0 || code > CHAR_9 ) &&
427
+ ( code < CHAR_UPPERCASE_A || code > CHAR_UPPERCASE_Z ) &&
428
+ ( code < CHAR_LOWERCASE_A || code > CHAR_LOWERCASE_Z ) )
414
429
break ;
415
430
}
416
431
if ( i === base . length ) {
0 commit comments