@@ -153,7 +153,7 @@ Module.builtinModules = builtinModules;
153153Module . _cache = Object . create ( null ) ;
154154Module . _pathCache = Object . create ( null ) ;
155155Module . _extensions = Object . create ( null ) ;
156- var modulePaths = [ ] ;
156+ let modulePaths = [ ] ;
157157Module . globalPaths = [ ] ;
158158
159159let patched = false ;
@@ -341,7 +341,7 @@ function toRealPath(requestPath) {
341341
342342// Given a path, check if the file exists with any of the set extensions
343343function tryExtensions ( p , exts , isMain ) {
344- for ( var i = 0 ; i < exts . length ; i ++ ) {
344+ for ( let i = 0 ; i < exts . length ; i ++ ) {
345345const filename = tryFile ( p + exts [ i ] , isMain ) ;
346346
347347if ( filename ) {
@@ -474,22 +474,22 @@ Module._findPath = function(request, paths, isMain) {
474474if ( entry )
475475return entry ;
476476
477- var exts ;
478- var trailingSlash = request . length > 0 &&
477+ let exts ;
478+ let trailingSlash = request . length > 0 &&
479479request . charCodeAt ( request . length - 1 ) === CHAR_FORWARD_SLASH ;
480480if ( ! trailingSlash ) {
481481trailingSlash = / (?: ^ | \/ ) \. ? \. $ / . test ( request ) ;
482482}
483483
484484// For each path
485- for ( var i = 0 ; i < paths . length ; i ++ ) {
485+ for ( let i = 0 ; i < paths . length ; i ++ ) {
486486// Don't search further if path doesn't exist
487487const curPath = paths [ i ] ;
488488if ( curPath && stat ( curPath ) < 1 ) continue ;
489- var basePath = resolveExports ( curPath , request , absoluteRequest ) ;
490- var filename ;
489+ const basePath = resolveExports ( curPath , request , absoluteRequest ) ;
490+ let filename ;
491491
492- var rc = stat ( basePath ) ;
492+ const rc = stat ( basePath ) ;
493493if ( ! trailingSlash ) {
494494if ( rc === 0 ) { // File.
495495if ( ! isMain ) {
@@ -556,9 +556,7 @@ if (isWindows) {
556556return [ from + 'node_modules' ] ;
557557
558558const paths = [ ] ;
559- var p = 0 ;
560- var last = from . length ;
561- for ( var i = from . length - 1 ; i >= 0 ; -- i ) {
559+ for ( let i = from . length - 1 , p = 0 , last = from . length ; i >= 0 ; -- i ) {
562560const code = from . charCodeAt ( i ) ;
563561// The path segment separator check ('\' and '/') was used to get
564562// node_modules path for every path segment.
@@ -597,9 +595,7 @@ if (isWindows) {
597595// to be absolute. Doing a fully-edge-case-correct path.split
598596// that works on both Windows and Posix is non-trivial.
599597const paths = [ ] ;
600- var p = 0 ;
601- var last = from . length ;
602- for ( var i = from . length - 1 ; i >= 0 ; -- i ) {
598+ for ( let i = from . length - 1 , p = 0 , last = from . length ; i >= 0 ; -- i ) {
603599const code = from . charCodeAt ( i ) ;
604600if ( code === CHAR_FORWARD_SLASH ) {
605601if ( p !== nmLen )
@@ -744,7 +740,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
744740return request ;
745741}
746742
747- var paths ;
743+ let paths ;
748744
749745if ( typeof options === 'object' && options !== null ) {
750746if ( Array . isArray ( options . paths ) ) {
@@ -760,12 +756,12 @@ Module._resolveFilename = function(request, parent, isMain, options) {
760756
761757paths = [ ] ;
762758
763- for ( var i = 0 ; i < options . paths . length ; i ++ ) {
759+ for ( let i = 0 ; i < options . paths . length ; i ++ ) {
764760const path = options . paths [ i ] ;
765761fakeParent . paths = Module . _nodeModulePaths ( path ) ;
766762const lookupPaths = Module . _resolveLookupPaths ( request , fakeParent ) ;
767763
768- for ( var j = 0 ; j < lookupPaths . length ; j ++ ) {
764+ for ( let j = 0 ; j < lookupPaths . length ; j ++ ) {
769765if ( ! paths . includes ( lookupPaths [ j ] ) )
770766paths . push ( lookupPaths [ j ] ) ;
771767}
@@ -784,7 +780,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
784780const filename = Module . _findPath ( request , paths , isMain ) ;
785781if ( ! filename ) {
786782const requireStack = [ ] ;
787- for ( var cursor = parent ;
783+ for ( let cursor = parent ;
788784cursor ;
789785cursor = cursor . parent ) {
790786requireStack . push ( cursor . filename || cursor . id ) ;
@@ -794,7 +790,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
794790message = message + '\nRequire stack:\n- ' + requireStack . join ( '\n- ' ) ;
795791}
796792// eslint-disable-next-line no-restricted-syntax
797- var err = new Error ( message ) ;
793+ const err = new Error ( message ) ;
798794err . code = 'MODULE_NOT_FOUND' ;
799795err . requireStack = requireStack ;
800796throw err ;
@@ -858,7 +854,7 @@ Module.prototype.require = function(id) {
858854
859855// Resolved path to process.argv[1] will be lazily placed here
860856// (needed for setting breakpoint when called with --inspect-brk)
861- var resolvedArgv ;
857+ let resolvedArgv ;
862858let hasPausedEntry = false ;
863859
864860// Run the file contents in the correct scope or sandbox. Expose
@@ -928,7 +924,7 @@ Module.prototype._compile = function(content, filename) {
928924compiledWrapper = compiled . function ;
929925}
930926
931- var inspectorWrapper = null ;
927+ let inspectorWrapper = null ;
932928if ( getOptionValue ( '--inspect-brk' ) && process . _eval == null ) {
933929if ( ! resolvedArgv ) {
934930// We enter the repl if we're not given a filename argument.
@@ -947,7 +943,7 @@ Module.prototype._compile = function(content, filename) {
947943}
948944const dirname = path . dirname ( filename ) ;
949945const require = makeRequireFunction ( this , redirects ) ;
950- var result ;
946+ let result ;
951947const exports = this . exports ;
952948const thisValue = exports ;
953949const module = this ;
@@ -1090,26 +1086,16 @@ function createRequire(filename) {
10901086Module . createRequire = createRequire ;
10911087
10921088Module . _initPaths = function ( ) {
1093- var homeDir ;
1094- var nodePath ;
1095- if ( isWindows ) {
1096- homeDir = process . env . USERPROFILE ;
1097- nodePath = process . env . NODE_PATH ;
1098- } else {
1099- homeDir = safeGetenv ( 'HOME' ) ;
1100- nodePath = safeGetenv ( 'NODE_PATH' ) ;
1101- }
1089+ const homeDir = isWindows ? process . env . USERPROFILE : safeGetenv ( 'HOME' ) ;
1090+ const nodePath = isWindows ? process . env . NODE_PATH : safeGetenv ( 'NODE_PATH' ) ;
11021091
1103- // $PREFIX/lib/node, where $PREFIX is the root of the Node.js installation.
1104- var prefixDir ;
11051092// process.execPath is $PREFIX/bin/node except on Windows where it is
1106- // $PREFIX\node.exe.
1107- if ( isWindows ) {
1108- prefixDir = path . resolve ( process . execPath , '..' ) ;
1109- } else {
1110- prefixDir = path . resolve ( process . execPath , '..' , '..' ) ;
1111- }
1112- var paths = [ path . resolve ( prefixDir , 'lib' , 'node' ) ] ;
1093+ // $PREFIX\node.exe where $PREFIX is the root of the Node.js installation.
1094+ const prefixDir = isWindows ?
1095+ path . resolve ( process . execPath , '..' ) :
1096+ path . resolve ( process . execPath , '..' , '..' ) ;
1097+
1098+ let paths = [ path . resolve ( prefixDir , 'lib' , 'node' ) ] ;
11131099
11141100if ( homeDir ) {
11151101paths . unshift ( path . resolve ( homeDir , '.node_libraries' ) ) ;
@@ -1143,7 +1129,7 @@ Module._preloadModules = function(requests) {
11431129throw e ;
11441130}
11451131}
1146- for ( var n = 0 ; n < requests . length ; n ++ )
1132+ for ( let n = 0 ; n < requests . length ; n ++ )
11471133parent . require ( requests [ n ] ) ;
11481134} ;
11491135
0 commit comments