@@ -153,7 +153,7 @@ Module.builtinModules = builtinModules;
153
153
Module . _cache = Object . create ( null ) ;
154
154
Module . _pathCache = Object . create ( null ) ;
155
155
Module . _extensions = Object . create ( null ) ;
156
- var modulePaths = [ ] ;
156
+ let modulePaths = [ ] ;
157
157
Module . globalPaths = [ ] ;
158
158
159
159
let patched = false ;
@@ -341,7 +341,7 @@ function toRealPath(requestPath) {
341
341
342
342
// Given a path, check if the file exists with any of the set extensions
343
343
function tryExtensions ( p , exts , isMain ) {
344
- for ( var i = 0 ; i < exts . length ; i ++ ) {
344
+ for ( let i = 0 ; i < exts . length ; i ++ ) {
345
345
const filename = tryFile ( p + exts [ i ] , isMain ) ;
346
346
347
347
if ( filename ) {
@@ -474,22 +474,22 @@ Module._findPath = function(request, paths, isMain) {
474
474
if ( entry )
475
475
return entry ;
476
476
477
- var exts ;
478
- var trailingSlash = request . length > 0 &&
477
+ let exts ;
478
+ let trailingSlash = request . length > 0 &&
479
479
request . charCodeAt ( request . length - 1 ) === CHAR_FORWARD_SLASH ;
480
480
if ( ! trailingSlash ) {
481
481
trailingSlash = / (?: ^ | \/ ) \. ? \. $ / . test ( request ) ;
482
482
}
483
483
484
484
// For each path
485
- for ( var i = 0 ; i < paths . length ; i ++ ) {
485
+ for ( let i = 0 ; i < paths . length ; i ++ ) {
486
486
// Don't search further if path doesn't exist
487
487
const curPath = paths [ i ] ;
488
488
if ( 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 ;
491
491
492
- var rc = stat ( basePath ) ;
492
+ const rc = stat ( basePath ) ;
493
493
if ( ! trailingSlash ) {
494
494
if ( rc === 0 ) { // File.
495
495
if ( ! isMain ) {
@@ -556,9 +556,7 @@ if (isWindows) {
556
556
return [ from + 'node_modules' ] ;
557
557
558
558
const 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 ) {
562
560
const code = from . charCodeAt ( i ) ;
563
561
// The path segment separator check ('\' and '/') was used to get
564
562
// node_modules path for every path segment.
@@ -597,9 +595,7 @@ if (isWindows) {
597
595
// to be absolute. Doing a fully-edge-case-correct path.split
598
596
// that works on both Windows and Posix is non-trivial.
599
597
const 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 ) {
603
599
const code = from . charCodeAt ( i ) ;
604
600
if ( code === CHAR_FORWARD_SLASH ) {
605
601
if ( p !== nmLen )
@@ -744,7 +740,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
744
740
return request ;
745
741
}
746
742
747
- var paths ;
743
+ let paths ;
748
744
749
745
if ( typeof options === 'object' && options !== null ) {
750
746
if ( Array . isArray ( options . paths ) ) {
@@ -760,12 +756,12 @@ Module._resolveFilename = function(request, parent, isMain, options) {
760
756
761
757
paths = [ ] ;
762
758
763
- for ( var i = 0 ; i < options . paths . length ; i ++ ) {
759
+ for ( let i = 0 ; i < options . paths . length ; i ++ ) {
764
760
const path = options . paths [ i ] ;
765
761
fakeParent . paths = Module . _nodeModulePaths ( path ) ;
766
762
const lookupPaths = Module . _resolveLookupPaths ( request , fakeParent ) ;
767
763
768
- for ( var j = 0 ; j < lookupPaths . length ; j ++ ) {
764
+ for ( let j = 0 ; j < lookupPaths . length ; j ++ ) {
769
765
if ( ! paths . includes ( lookupPaths [ j ] ) )
770
766
paths . push ( lookupPaths [ j ] ) ;
771
767
}
@@ -784,7 +780,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
784
780
const filename = Module . _findPath ( request , paths , isMain ) ;
785
781
if ( ! filename ) {
786
782
const requireStack = [ ] ;
787
- for ( var cursor = parent ;
783
+ for ( let cursor = parent ;
788
784
cursor ;
789
785
cursor = cursor . parent ) {
790
786
requireStack . push ( cursor . filename || cursor . id ) ;
@@ -794,7 +790,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
794
790
message = message + '\nRequire stack:\n- ' + requireStack . join ( '\n- ' ) ;
795
791
}
796
792
// eslint-disable-next-line no-restricted-syntax
797
- var err = new Error ( message ) ;
793
+ const err = new Error ( message ) ;
798
794
err . code = 'MODULE_NOT_FOUND' ;
799
795
err . requireStack = requireStack ;
800
796
throw err ;
@@ -858,7 +854,7 @@ Module.prototype.require = function(id) {
858
854
859
855
// Resolved path to process.argv[1] will be lazily placed here
860
856
// (needed for setting breakpoint when called with --inspect-brk)
861
- var resolvedArgv ;
857
+ let resolvedArgv ;
862
858
let hasPausedEntry = false ;
863
859
864
860
// Run the file contents in the correct scope or sandbox. Expose
@@ -928,7 +924,7 @@ Module.prototype._compile = function(content, filename) {
928
924
compiledWrapper = compiled . function ;
929
925
}
930
926
931
- var inspectorWrapper = null ;
927
+ let inspectorWrapper = null ;
932
928
if ( getOptionValue ( '--inspect-brk' ) && process . _eval == null ) {
933
929
if ( ! resolvedArgv ) {
934
930
// We enter the repl if we're not given a filename argument.
@@ -947,7 +943,7 @@ Module.prototype._compile = function(content, filename) {
947
943
}
948
944
const dirname = path . dirname ( filename ) ;
949
945
const require = makeRequireFunction ( this , redirects ) ;
950
- var result ;
946
+ let result ;
951
947
const exports = this . exports ;
952
948
const thisValue = exports ;
953
949
const module = this ;
@@ -1090,26 +1086,16 @@ function createRequire(filename) {
1090
1086
Module . createRequire = createRequire ;
1091
1087
1092
1088
Module . _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' ) ;
1102
1091
1103
- // $PREFIX/lib/node, where $PREFIX is the root of the Node.js installation.
1104
- var prefixDir ;
1105
1092
// 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' ) ] ;
1113
1099
1114
1100
if ( homeDir ) {
1115
1101
paths . unshift ( path . resolve ( homeDir , '.node_libraries' ) ) ;
@@ -1143,7 +1129,7 @@ Module._preloadModules = function(requests) {
1143
1129
throw e ;
1144
1130
}
1145
1131
}
1146
- for ( var n = 0 ; n < requests . length ; n ++ )
1132
+ for ( let n = 0 ; n < requests . length ; n ++ )
1147
1133
parent . require ( requests [ n ] ) ;
1148
1134
} ;
1149
1135
0 commit comments