Skip to content

Commit 614949d

Browse files
VinceOPSMylesBorins
authored andcommitted
lib: replace var with let and const in readline.js
PR-URL: #30377 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> 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 12d7d64 commit 614949d

1 file changed

Lines changed: 45 additions & 47 deletions

File tree

‎lib/readline.js‎

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ function Interface(input, output, completer, terminal) {
9494
this.escapeCodeTimeout=ESCAPE_CODE_TIMEOUT;
9595

9696
EventEmitter.call(this);
97-
varhistorySize;
98-
varremoveHistoryDuplicates=false;
97+
lethistorySize;
98+
letremoveHistoryDuplicates=false;
9999
letcrlfDelay;
100100
letprompt='> ';
101101

@@ -258,10 +258,9 @@ Object.defineProperty(Interface.prototype, 'columns', {
258258
configurable: true,
259259
enumerable: true,
260260
get: function(){
261-
varcolumns=Infinity;
262261
if(this.output&&this.output.columns)
263-
columns=this.output.columns;
264-
returncolumns;
262+
returnthis.output.columns;
263+
returnInfinity;
265264
}
266265
});
267266

@@ -308,7 +307,7 @@ Interface.prototype.question = function(query, cb) {
308307

309308
Interface.prototype._onLine=function(line){
310309
if(this._questionCallback){
311-
varcb=this._questionCallback;
310+
constcb=this._questionCallback;
312311
this._questionCallback=null;
313312
this.setPrompt(this._oldPrompt);
314313
cb(line);
@@ -435,7 +434,7 @@ Interface.prototype._normalWrite = function(b) {
435434
if(b===undefined){
436435
return;
437436
}
438-
varstring=this._decoder.write(b);
437+
letstring=this._decoder.write(b);
439438
if(this._sawReturnAt&&
440439
Date.now()-this._sawReturnAt<=this.crlfDelay){
441440
string=string.replace(/^\n/,'');
@@ -453,11 +452,11 @@ Interface.prototype._normalWrite = function(b) {
453452
this._sawReturnAt=string.endsWith('\r') ? Date.now() : 0;
454453

455454
// Got one or more newlines; process into "line" events
456-
varlines=string.split(lineEnding);
455+
constlines=string.split(lineEnding);
457456
// Either '' or (conceivably) the unfinished portion of the next line
458457
string=lines.pop();
459458
this._line_buffer=string;
460-
for(varn=0;n<lines.length;n++)
459+
for(letn=0;n<lines.length;n++)
461460
this._onLine(lines[n]);
462461
}elseif(string){
463462
// No newlines this time, save what we have for next time
@@ -467,8 +466,8 @@ Interface.prototype._normalWrite = function(b) {
467466

468467
Interface.prototype._insertString=function(c){
469468
if(this.cursor<this.line.length){
470-
varbeg=this.line.slice(0,this.cursor);
471-
varend=this.line.slice(this.cursor,this.line.length);
469+
constbeg=this.line.slice(0,this.cursor);
470+
constend=this.line.slice(this.cursor,this.line.length);
472471
this.line=beg+c+end;
473472
this.cursor+=c.length;
474473
this._refreshLine();
@@ -505,16 +504,16 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) {
505504
// Apply/show completions.
506505
if(lastKeypressWasTab){
507506
self._writeToOutput('\r\n');
508-
varwidth=completions.reduce(functioncompletionReducer(a,b){
507+
constwidth=completions.reduce(functioncompletionReducer(a,b){
509508
returna.length>b.length ? a : b;
510509
}).length+2;// 2 space padding
511-
varmaxColumns=Math.floor(self.columns/width);
510+
letmaxColumns=Math.floor(self.columns/width);
512511
if(!maxColumns||maxColumns===Infinity){
513512
maxColumns=1;
514513
}
515-
vargroup=[];
516-
for(vari=0;i<completions.length;i++){
517-
varc=completions[i];
514+
letgroup=[];
515+
for(leti=0;i<completions.length;i++){
516+
constc=completions[i];
518517
if(c===''){
519518
handleGroup(self,group,width,maxColumns);
520519
group=[];
@@ -526,8 +525,8 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) {
526525
}
527526

528527
// If there is a common prefix to all matches, then apply that portion.
529-
varf=completions.filter((e)=>e);
530-
varprefix=commonPrefix(f);
528+
constf=completions.filter((e)=>e);
529+
constprefix=commonPrefix(f);
531530
if(prefix.length>completeOn.length){
532531
self._insertString(prefix.slice(completeOn.length));
533532
}
@@ -543,16 +542,16 @@ function handleGroup(self, group, width, maxColumns) {
543542
return;
544543
}
545544
constminRows=Math.ceil(group.length/maxColumns);
546-
for(varrow=0;row<minRows;row++){
547-
for(varcol=0;col<maxColumns;col++){
548-
varidx=row*maxColumns+col;
545+
for(letrow=0;row<minRows;row++){
546+
for(letcol=0;col<maxColumns;col++){
547+
constidx=row*maxColumns+col;
549548
if(idx>=group.length){
550549
break;
551550
}
552-
varitem=group[idx];
551+
constitem=group[idx];
553552
self._writeToOutput(item);
554553
if(col<maxColumns-1){
555-
for(vars=0;s<width-item.length;s++){
554+
for(lets=0;s<width-item.length;s++){
556555
self._writeToOutput(' ');
557556
}
558557
}
@@ -570,7 +569,7 @@ function commonPrefix(strings) {
570569
constsorted=strings.slice().sort();
571570
constmin=sorted[0];
572571
constmax=sorted[sorted.length-1];
573-
for(vari=0,len=min.length;i<len;i++){
572+
for(leti=0,len=min.length;i<len;i++){
574573
if(min[i]!==max[i]){
575574
returnmin.slice(0,i);
576575
}
@@ -583,18 +582,18 @@ Interface.prototype._wordLeft = function() {
583582
if(this.cursor>0){
584583
// Reverse the string and match a word near beginning
585584
// to avoid quadratic time complexity
586-
varleading=this.line.slice(0,this.cursor);
587-
varreversed=leading.split('').reverse().join('');
588-
varmatch=reversed.match(/^\s*(?:[^\w\s]+|\w+)?/);
585+
constleading=this.line.slice(0,this.cursor);
586+
constreversed=leading.split('').reverse().join('');
587+
constmatch=reversed.match(/^\s*(?:[^\w\s]+|\w+)?/);
589588
this._moveCursor(-match[0].length);
590589
}
591590
};
592591

593592

594593
Interface.prototype._wordRight=function(){
595594
if(this.cursor<this.line.length){
596-
vartrailing=this.line.slice(this.cursor);
597-
varmatch=trailing.match(/^(?:\s+|[^\w\s]+|\w+)\s*/);
595+
consttrailing=this.line.slice(this.cursor);
596+
constmatch=trailing.match(/^(?:\s+|[^\w\s]+|\w+)\s*/);
598597
this._moveCursor(match[0].length);
599598
}
600599
};
@@ -643,9 +642,9 @@ Interface.prototype._deleteWordLeft = function() {
643642
if(this.cursor>0){
644643
// Reverse the string and match a word near beginning
645644
// to avoid quadratic time complexity
646-
varleading=this.line.slice(0,this.cursor);
647-
varreversed=leading.split('').reverse().join('');
648-
varmatch=reversed.match(/^\s*(?:[^\w\s]+|\w+)?/);
645+
letleading=this.line.slice(0,this.cursor);
646+
constreversed=leading.split('').reverse().join('');
647+
constmatch=reversed.match(/^\s*(?:[^\w\s]+|\w+)?/);
649648
leading=leading.slice(0,leading.length-match[0].length);
650649
this.line=leading+this.line.slice(this.cursor,this.line.length);
651650
this.cursor=leading.length;
@@ -656,8 +655,8 @@ Interface.prototype._deleteWordLeft = function() {
656655

657656
Interface.prototype._deleteWordRight=function(){
658657
if(this.cursor<this.line.length){
659-
vartrailing=this.line.slice(this.cursor);
660-
varmatch=trailing.match(/^(?:\s+|\W+|\w+)\s*/);
658+
consttrailing=this.line.slice(this.cursor);
659+
constmatch=trailing.match(/^(?:\s+|\W+|\w+)\s*/);
661660
this.line=this.line.slice(0,this.cursor)+
662661
trailing.slice(match[0].length);
663662
this._refreshLine();
@@ -723,13 +722,12 @@ Interface.prototype._historyPrev = function() {
723722

724723
// Returns the last character's display position of the given string
725724
Interface.prototype._getDisplayPos=function(str){
726-
varoffset=0;
725+
letoffset=0;
727726
constcol=this.columns;
728-
varrow=0;
729-
varcode;
727+
letrow=0;
730728
str=stripVTControlCharacters(str);
731-
for(vari=0,len=str.length;i<len;i++){
732-
code=str.codePointAt(i);
729+
for(leti=0,len=str.length;i<len;i++){
730+
constcode=str.codePointAt(i);
733731
if(code>=kUTF16SurrogateThreshold){// Surrogates.
734732
i++;
735733
}
@@ -761,8 +759,8 @@ Interface.prototype._getCursorPos = function() {
761759
conststrBeforeCursor=this._prompt+this.line.substring(0,this.cursor);
762760
constdispPos=this._getDisplayPos(
763761
stripVTControlCharacters(strBeforeCursor));
764-
varcols=dispPos.cols;
765-
varrows=dispPos.rows;
762+
letcols=dispPos.cols;
763+
letrows=dispPos.rows;
766764
// If the cursor is on a full-width character which steps over the line,
767765
// move the cursor to the beginning of the next line.
768766
if(cols+1===columns&&
@@ -790,8 +788,8 @@ Interface.prototype._moveCursor = function(dx) {
790788

791789
// Check if cursors are in the same line
792790
if(oldPos.rows===newPos.rows){
793-
vardiffCursor=this.cursor-oldcursor;
794-
vardiffWidth;
791+
constdiffCursor=this.cursor-oldcursor;
792+
letdiffWidth;
795793
if(diffCursor<0){
796794
diffWidth=-getStringWidth(
797795
this.line.substring(this.cursor,oldcursor)
@@ -1072,8 +1070,8 @@ Interface.prototype._ttyWrite = function(s, key) {
10721070

10731071
default:
10741072
if(typeofs==='string'&&s){
1075-
varlines=s.split(/\r\n|\n|\r/);
1076-
for(vari=0,len=lines.length;i<len;i++){
1073+
constlines=s.split(/\r\n|\n|\r/);
1074+
for(leti=0,len=lines.length;i<len;i++){
10771075
if(i>0){
10781076
this._line();
10791077
}
@@ -1136,15 +1134,15 @@ function emitKeypressEvents(stream, iface) {
11361134

11371135
functiononData(b){
11381136
if(stream.listenerCount('keypress')>0){
1139-
varr=stream[KEYPRESS_DECODER].write(b);
1137+
constr=stream[KEYPRESS_DECODER].write(b);
11401138
if(r){
11411139
clearTimeout(timeoutId);
11421140

11431141
if(iface){
11441142
iface._sawKeyPress=r.length===1;
11451143
}
11461144

1147-
for(vari=0;i<r.length;i++){
1145+
for(leti=0;i<r.length;i++){
11481146
if(r[i]==='\t'&&typeofr[i+1]==='string'&&iface){
11491147
iface.isCompletionEnabled=false;
11501148
}

0 commit comments

Comments
 (0)