@@ -158,7 +158,7 @@ Module.builtinModules = builtinModules;
158158Module . _cache = Object . create ( null ) ;
159159Module . _pathCache = Object . create ( null ) ;
160160Module . _extensions = Object . create ( null ) ;
161- var modulePaths = [ ] ;
161+ let modulePaths = [ ] ;
162162Module . globalPaths = [ ] ;
163163
164164let patched = false ;
@@ -347,7 +347,7 @@ function toRealPath(requestPath) {
347347
348348// Given a path, check if the file exists with any of the set extensions
349349function tryExtensions ( p , exts , isMain ) {
350- for ( var i = 0 ; i < exts . length ; i ++ ) {
350+ for ( let i = 0 ; i < exts . length ; i ++ ) {
351351 const filename = tryFile ( p + exts [ i ] , isMain ) ;
352352
353353 if ( filename ) {
@@ -625,22 +625,22 @@ Module._findPath = function(request, paths, isMain) {
625625 if ( entry )
626626 return entry ;
627627
628- var exts ;
629- var trailingSlash = request . length > 0 &&
628+ let exts ;
629+ let trailingSlash = request . length > 0 &&
630630 request . charCodeAt ( request . length - 1 ) === CHAR_FORWARD_SLASH ;
631631 if ( ! trailingSlash ) {
632632 trailingSlash = / (?: ^ | \/ ) \. ? \. $ / . test ( request ) ;
633633 }
634634
635635 // For each path
636- for ( var i = 0 ; i < paths . length ; i ++ ) {
636+ for ( let i = 0 ; i < paths . length ; i ++ ) {
637637 // Don't search further if path doesn't exist
638638 const curPath = paths [ i ] ;
639639 if ( curPath && stat ( curPath ) < 1 ) continue ;
640- var basePath = resolveExports ( curPath , request , absoluteRequest ) ;
641- var filename ;
640+ const basePath = resolveExports ( curPath , request , absoluteRequest ) ;
641+ let filename ;
642642
643- var rc = stat ( basePath ) ;
643+ const rc = stat ( basePath ) ;
644644 if ( ! trailingSlash ) {
645645 if ( rc === 0 ) { // File.
646646 if ( ! isMain ) {
@@ -714,9 +714,7 @@ if (isWindows) {
714714 return [ from + 'node_modules' ] ;
715715
716716 const paths = [ ] ;
717- var p = 0 ;
718- var last = from . length ;
719- for ( var i = from . length - 1 ; i >= 0 ; -- i ) {
717+ for ( let i = from . length - 1 , p = 0 , last = from . length ; i >= 0 ; -- i ) {
720718 const code = from . charCodeAt ( i ) ;
721719 // The path segment separator check ('\' and '/') was used to get
722720 // node_modules path for every path segment.
@@ -755,9 +753,7 @@ if (isWindows) {
755753 // to be absolute. Doing a fully-edge-case-correct path.split
756754 // that works on both Windows and Posix is non-trivial.
757755 const paths = [ ] ;
758- var p = 0 ;
759- var last = from . length ;
760- for ( var i = from . length - 1 ; i >= 0 ; -- i ) {
756+ for ( let i = from . length - 1 , p = 0 , last = from . length ; i >= 0 ; -- i ) {
761757 const code = from . charCodeAt ( i ) ;
762758 if ( code === CHAR_FORWARD_SLASH ) {
763759 if ( p !== nmLen )
@@ -956,7 +952,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
956952 return request ;
957953 }
958954
959- var paths ;
955+ let paths ;
960956
961957 if ( typeof options === 'object' && options !== null ) {
962958 if ( Array . isArray ( options . paths ) ) {
@@ -972,12 +968,12 @@ Module._resolveFilename = function(request, parent, isMain, options) {
972968
973969 paths = [ ] ;
974970
975- for ( var i = 0 ; i < options . paths . length ; i ++ ) {
971+ for ( let i = 0 ; i < options . paths . length ; i ++ ) {
976972 const path = options . paths [ i ] ;
977973 fakeParent . paths = Module . _nodeModulePaths ( path ) ;
978974 const lookupPaths = Module . _resolveLookupPaths ( request , fakeParent ) ;
979975
980- for ( var j = 0 ; j < lookupPaths . length ; j ++ ) {
976+ for ( let j = 0 ; j < lookupPaths . length ; j ++ ) {
981977 if ( ! paths . includes ( lookupPaths [ j ] ) )
982978 paths . push ( lookupPaths [ j ] ) ;
983979 }
@@ -996,7 +992,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
996992 const filename = Module . _findPath ( request , paths , isMain ) ;
997993 if ( ! filename ) {
998994 const requireStack = [ ] ;
999- for ( var cursor = parent ;
995+ for ( let cursor = parent ;
1000996 cursor ;
1001997 cursor = cursor . parent ) {
1002998 requireStack . push ( cursor . filename || cursor . id ) ;
@@ -1006,7 +1002,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
10061002 message = message + '\nRequire stack:\n- ' + requireStack . join ( '\n- ' ) ;
10071003 }
10081004 // eslint-disable-next-line no-restricted-syntax
1009- var err = new Error ( message ) ;
1005+ const err = new Error ( message ) ;
10101006 err . code = 'MODULE_NOT_FOUND' ;
10111007 err . requireStack = requireStack ;
10121008 throw err ;
@@ -1077,7 +1073,7 @@ Module.prototype.require = function(id) {
10771073
10781074// Resolved path to process.argv[1] will be lazily placed here
10791075// (needed for setting breakpoint when called with --inspect-brk)
1080- var resolvedArgv ;
1076+ let resolvedArgv ;
10811077let hasPausedEntry = false ;
10821078
10831079function wrapSafe ( filename , content , cjsModuleInstance ) {
@@ -1145,7 +1141,7 @@ Module.prototype._compile = function(content, filename) {
11451141 maybeCacheSourceMap ( filename , content , this ) ;
11461142 const compiledWrapper = wrapSafe ( filename , content , this ) ;
11471143
1148- var inspectorWrapper = null ;
1144+ let inspectorWrapper = null ;
11491145 if ( getOptionValue ( '--inspect-brk' ) && process . _eval == null ) {
11501146 if ( ! resolvedArgv ) {
11511147 // We enter the repl if we're not given a filename argument.
@@ -1164,7 +1160,7 @@ Module.prototype._compile = function(content, filename) {
11641160 }
11651161 const dirname = path . dirname ( filename ) ;
11661162 const require = makeRequireFunction ( this , redirects ) ;
1167- var result ;
1163+ let result ;
11681164 const exports = this . exports ;
11691165 const thisValue = exports ;
11701166 const module = this ;
@@ -1303,26 +1299,16 @@ function createRequire(filename) {
13031299Module . createRequire = createRequire ;
13041300
13051301Module . _initPaths = function ( ) {
1306- var homeDir ;
1307- var nodePath ;
1308- if ( isWindows ) {
1309- homeDir = process . env . USERPROFILE ;
1310- nodePath = process . env . NODE_PATH ;
1311- } else {
1312- homeDir = safeGetenv ( 'HOME' ) ;
1313- nodePath = safeGetenv ( 'NODE_PATH' ) ;
1314- }
1302+ const homeDir = isWindows ? process . env . USERPROFILE : safeGetenv ( 'HOME' ) ;
1303+ const nodePath = isWindows ? process . env . NODE_PATH : safeGetenv ( 'NODE_PATH' ) ;
13151304
1316- // $PREFIX/lib/node, where $PREFIX is the root of the Node.js installation.
1317- var prefixDir ;
13181305 // process.execPath is $PREFIX/bin/node except on Windows where it is
1319- // $PREFIX\node.exe.
1320- if ( isWindows ) {
1321- prefixDir = path . resolve ( process . execPath , '..' ) ;
1322- } else {
1323- prefixDir = path . resolve ( process . execPath , '..' , '..' ) ;
1324- }
1325- var paths = [ path . resolve ( prefixDir , 'lib' , 'node' ) ] ;
1306+ // $PREFIX\node.exe where $PREFIX is the root of the Node.js installation.
1307+ const prefixDir = isWindows ?
1308+ path . resolve ( process . execPath , '..' ) :
1309+ path . resolve ( process . execPath , '..' , '..' ) ;
1310+
1311+ let paths = [ path . resolve ( prefixDir , 'lib' , 'node' ) ] ;
13261312
13271313 if ( homeDir ) {
13281314 paths . unshift ( path . resolve ( homeDir , '.node_libraries' ) ) ;
@@ -1356,7 +1342,7 @@ Module._preloadModules = function(requests) {
13561342 throw e ;
13571343 }
13581344 }
1359- for ( var n = 0 ; n < requests . length ; n ++ )
1345+ for ( let n = 0 ; n < requests . length ; n ++ )
13601346 parent . require ( requests [ n ] ) ;
13611347} ;
13621348
0 commit comments