@@ -47,6 +47,19 @@ module.exports = Module;
4747const internalESModule = require ( 'internal/process/modules' ) ;
4848const ModuleJob = require ( 'internal/loader/ModuleJob' ) ;
4949const 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' ) ;
5063
5164function stat ( filename ) {
5265 filename = path . toNamespacedPath ( filename ) ;
@@ -201,7 +214,7 @@ Module._findPath = function(request, paths, isMain) {
201214
202215 var exts ;
203216 var trailingSlash = request . length > 0 &&
204- request . charCodeAt ( request . length - 1 ) === 47 /*/*/ ;
217+ request . charCodeAt ( request . length - 1 ) === CHAR_FORWARD_SLASH ;
205218
206219 // For each path
207220 for ( var i = 0 ; i < paths . length ; i ++ ) {
@@ -276,8 +289,8 @@ if (process.platform === 'win32') {
276289
277290 // return root node_modules when path is 'D:\\'.
278291 // 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 )
281294 return [ from + 'node_modules' ] ;
282295
283296 const paths = [ ] ;
@@ -290,7 +303,9 @@ if (process.platform === 'win32') {
290303 // Use colon as an extra condition since we can get node_modules
291304 // path for drive root like 'C:\node_modules' and don't need to
292305 // 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 ) {
294309 if ( p !== nmLen )
295310 paths . push ( from . slice ( 0 , last ) + '\\node_modules' ) ;
296311 last = i ;
@@ -324,7 +339,7 @@ if (process.platform === 'win32') {
324339 var last = from . length ;
325340 for ( var i = from . length - 1 ; i >= 0 ; -- i ) {
326341 const code = from . charCodeAt ( i ) ;
327- if ( code === 47 /*/*/ ) {
342+ if ( code === CHAR_FORWARD_SLASH ) {
328343 if ( p !== nmLen )
329344 paths . push ( from . slice ( 0 , last ) + '/node_modules' ) ;
330345 last = i ;
@@ -357,9 +372,9 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
357372
358373 // Check for relative path
359374 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 ) ) {
363378 var paths = modulePaths ;
364379 if ( parent ) {
365380 if ( ! parent . paths )
@@ -407,10 +422,10 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
407422 // We matched 'index.', let's validate the rest
408423 for ( ; i < base . length ; ++ i ) {
409424 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 ) )
414429 break ;
415430 }
416431 if ( i === base . length ) {
0 commit comments