Skip to content

Commit bd853cc

Browse files
khoumaniMylesBorins
authored andcommitted
lib: replace var with let/const
PR-URL: #30440 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 793d360 commit bd853cc

1 file changed

Lines changed: 27 additions & 41 deletions

File tree

‎lib/internal/modules/cjs/loader.js‎

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Module.builtinModules = builtinModules;
153153
Module._cache=Object.create(null);
154154
Module._pathCache=Object.create(null);
155155
Module._extensions=Object.create(null);
156-
varmodulePaths=[];
156+
letmodulePaths=[];
157157
Module.globalPaths=[];
158158

159159
letpatched=false;
@@ -341,7 +341,7 @@ function toRealPath(requestPath) {
341341

342342
// Given a path, check if the file exists with any of the set extensions
343343
functiontryExtensions(p,exts,isMain){
344-
for(vari=0;i<exts.length;i++){
344+
for(leti=0;i<exts.length;i++){
345345
constfilename=tryFile(p+exts[i],isMain);
346346

347347
if(filename){
@@ -474,22 +474,22 @@ Module._findPath = function(request, paths, isMain) {
474474
if(entry)
475475
returnentry;
476476

477-
varexts;
478-
vartrailingSlash=request.length>0&&
477+
letexts;
478+
lettrailingSlash=request.length>0&&
479479
request.charCodeAt(request.length-1)===CHAR_FORWARD_SLASH;
480480
if(!trailingSlash){
481481
trailingSlash=/(?:^|\/)\.?\.$/.test(request);
482482
}
483483

484484
// For each path
485-
for(vari=0;i<paths.length;i++){
485+
for(leti=0;i<paths.length;i++){
486486
// Don't search further if path doesn't exist
487487
constcurPath=paths[i];
488488
if(curPath&&stat(curPath)<1)continue;
489-
varbasePath=resolveExports(curPath,request,absoluteRequest);
490-
varfilename;
489+
constbasePath=resolveExports(curPath,request,absoluteRequest);
490+
letfilename;
491491

492-
varrc=stat(basePath);
492+
constrc=stat(basePath);
493493
if(!trailingSlash){
494494
if(rc===0){// File.
495495
if(!isMain){
@@ -556,9 +556,7 @@ if (isWindows) {
556556
return[from+'node_modules'];
557557

558558
constpaths=[];
559-
varp=0;
560-
varlast=from.length;
561-
for(vari=from.length-1;i>=0;--i){
559+
for(leti=from.length-1,p=0,last=from.length;i>=0;--i){
562560
constcode=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.
599597
constpaths=[];
600-
varp=0;
601-
varlast=from.length;
602-
for(vari=from.length-1;i>=0;--i){
598+
for(leti=from.length-1,p=0,last=from.length;i>=0;--i){
603599
constcode=from.charCodeAt(i);
604600
if(code===CHAR_FORWARD_SLASH){
605601
if(p!==nmLen)
@@ -744,7 +740,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
744740
returnrequest;
745741
}
746742

747-
varpaths;
743+
letpaths;
748744

749745
if(typeofoptions==='object'&&options!==null){
750746
if(Array.isArray(options.paths)){
@@ -760,12 +756,12 @@ Module._resolveFilename = function(request, parent, isMain, options) {
760756

761757
paths=[];
762758

763-
for(vari=0;i<options.paths.length;i++){
759+
for(leti=0;i<options.paths.length;i++){
764760
constpath=options.paths[i];
765761
fakeParent.paths=Module._nodeModulePaths(path);
766762
constlookupPaths=Module._resolveLookupPaths(request,fakeParent);
767763

768-
for(varj=0;j<lookupPaths.length;j++){
764+
for(letj=0;j<lookupPaths.length;j++){
769765
if(!paths.includes(lookupPaths[j]))
770766
paths.push(lookupPaths[j]);
771767
}
@@ -784,7 +780,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
784780
constfilename=Module._findPath(request,paths,isMain);
785781
if(!filename){
786782
constrequireStack=[];
787-
for(varcursor=parent;
783+
for(letcursor=parent;
788784
cursor;
789785
cursor=cursor.parent){
790786
requireStack.push(cursor.filename||cursor.id);
@@ -794,7 +790,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
794790
message=message+'\nRequire stack:\n- '+requireStack.join('\n- ');
795791
}
796792
// eslint-disable-next-line no-restricted-syntax
797-
varerr=newError(message);
793+
consterr=newError(message);
798794
err.code='MODULE_NOT_FOUND';
799795
err.requireStack=requireStack;
800796
throwerr;
@@ -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-
varresolvedArgv;
857+
letresolvedArgv;
862858
lethasPausedEntry=false;
863859

864860
// Run the file contents in the correct scope or sandbox. Expose
@@ -928,7 +924,7 @@ Module.prototype._compile = function(content, filename) {
928924
compiledWrapper=compiled.function;
929925
}
930926

931-
varinspectorWrapper=null;
927+
letinspectorWrapper=null;
932928
if(getOptionValue('--inspect-brk')&&process._eval==null){
933929
if(!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
}
948944
constdirname=path.dirname(filename);
949945
constrequire=makeRequireFunction(this,redirects);
950-
varresult;
946+
letresult;
951947
constexports=this.exports;
952948
constthisValue=exports;
953949
constmodule=this;
@@ -1090,26 +1086,16 @@ function createRequire(filename) {
10901086
Module.createRequire=createRequire;
10911087

10921088
Module._initPaths=function(){
1093-
varhomeDir;
1094-
varnodePath;
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+
consthomeDir=isWindows ? process.env.USERPROFILE : safeGetenv('HOME');
1090+
constnodePath=isWindows ? process.env.NODE_PATH : safeGetenv('NODE_PATH');
11021091

1103-
// $PREFIX/lib/node, where $PREFIX is the root of the Node.js installation.
1104-
varprefixDir;
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-
varpaths=[path.resolve(prefixDir,'lib','node')];
1093+
// $PREFIX\node.exe where $PREFIX is the root of the Node.js installation.
1094+
constprefixDir=isWindows ?
1095+
path.resolve(process.execPath,'..') :
1096+
path.resolve(process.execPath,'..','..');
1097+
1098+
letpaths=[path.resolve(prefixDir,'lib','node')];
11131099

11141100
if(homeDir){
11151101
paths.unshift(path.resolve(homeDir,'.node_libraries'));
@@ -1143,7 +1129,7 @@ Module._preloadModules = function(requests) {
11431129
throwe;
11441130
}
11451131
}
1146-
for(varn=0;n<requests.length;n++)
1132+
for(letn=0;n<requests.length;n++)
11471133
parent.require(requests[n]);
11481134
};
11491135

0 commit comments

Comments
 (0)