Skip to content

Commit 1413377

Browse files
xefimxtargos
authored andcommitted
url: replace var with let in lib/url.js
PR-URL: #30281 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 9d6c293 commit 1413377

1 file changed

Lines changed: 50 additions & 50 deletions

File tree

‎lib/url.js‎

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
157157
// Copy chrome, IE, opera backslash-handling behavior.
158158
// Back slashes before the query string get converted to forward slashes
159159
// See: https://code.google.com/p/chromium/issues/detail?id=25916
160-
varhasHash=false;
161-
varstart=-1;
162-
varend=-1;
163-
varrest='';
164-
varlastPos=0;
165-
vari=0;
166-
for(varinWs=false,split=false;i<url.length;++i){
160+
lethasHash=false;
161+
letstart=-1;
162+
letend=-1;
163+
letrest='';
164+
letlastPos=0;
165+
leti=0;
166+
for(letinWs=false,split=false;i<url.length;++i){
167167
constcode=url.charCodeAt(i);
168168

169169
// Find first and last non-whitespace characters for trimming
@@ -292,9 +292,9 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
292292
// http://a@b@c/ => user:a@b host:c
293293
// http://a@b?@c => user:a host:b path:/?@c
294294

295-
varhostEnd=-1;
296-
varatSign=-1;
297-
varnonHost=-1;
295+
lethostEnd=-1;
296+
letatSign=-1;
297+
letnonHost=-1;
298298
for(i=0;i<rest.length;++i){
299299
switch(rest.charCodeAt(i)){
300300
caseCHAR_TAB:
@@ -356,11 +356,11 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
356356
if(typeofthis.hostname!=='string')
357357
this.hostname='';
358358

359-
varhostname=this.hostname;
359+
consthostname=this.hostname;
360360

361361
// If hostname begins with [ and ends with ]
362362
// assume that it's an IPv6 address.
363-
varipv6Hostname=hostname.charCodeAt(0)===CHAR_LEFT_SQUARE_BRACKET&&
363+
constipv6Hostname=hostname.charCodeAt(0)===CHAR_LEFT_SQUARE_BRACKET&&
364364
hostname.charCodeAt(hostname.length-1)===CHAR_RIGHT_SQUARE_BRACKET;
365365

366366
// validate a little.
@@ -386,8 +386,8 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
386386
this.hostname=toASCII(this.hostname,true);
387387
}
388388

389-
varp=this.port ? ':'+this.port : '';
390-
varh=this.hostname||'';
389+
constp=this.port ? ':'+this.port : '';
390+
consth=this.hostname||'';
391391
this.host=h+p;
392392

393393
// strip [ and ] from the hostname
@@ -409,8 +409,8 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
409409
rest=autoEscapeStr(rest);
410410
}
411411

412-
varquestionIdx=-1;
413-
varhashIdx=-1;
412+
letquestionIdx=-1;
413+
lethashIdx=-1;
414414
for(i=0;i<rest.length;++i){
415415
constcode=rest.charCodeAt(i);
416416
if(code===CHAR_HASH){
@@ -467,7 +467,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
467467
};
468468

469469
functiongetHostname(self,rest,hostname){
470-
for(vari=0;i<hostname.length;++i){
470+
for(leti=0;i<hostname.length;++i){
471471
constcode=hostname.charCodeAt(i);
472472
constisValid=(code>=CHAR_LOWERCASE_A&&code<=CHAR_LOWERCASE_Z)||
473473
code===CHAR_DOT||
@@ -509,11 +509,11 @@ const escapedCodes = [
509509
// Also escape single quotes in case of an XSS attack.
510510
// Return the escaped string.
511511
functionautoEscapeStr(rest){
512-
varescaped='';
513-
varlastEscapedPos=0;
514-
for(vari=0;i<rest.length;++i){
512+
letescaped='';
513+
letlastEscapedPos=0;
514+
for(leti=0;i<rest.length;++i){
515515
// `escaped` contains substring up to the last escaped character.
516-
varescapedChar=escapedCodes[rest.charCodeAt(i)];
516+
constescapedChar=escapedCodes[rest.charCodeAt(i)];
517517
if(escapedChar){
518518
// Concat if there are ordinary characters in the middle.
519519
if(i>lastEscapedPos)
@@ -544,7 +544,7 @@ function urlFormat(urlObject, options) {
544544
thrownewERR_INVALID_ARG_TYPE('urlObject',
545545
['Object','string'],urlObject);
546546
}elseif(!(urlObjectinstanceofUrl)){
547-
varformat=urlObject[formatSymbol];
547+
constformat=urlObject[formatSymbol];
548548
returnformat ?
549549
format.call(urlObject,options) :
550550
Url.prototype.format.call(urlObject);
@@ -570,17 +570,17 @@ const noEscapeAuth = [
570570
];
571571

572572
Url.prototype.format=functionformat(){
573-
varauth=this.auth||'';
573+
letauth=this.auth||'';
574574
if(auth){
575575
auth=encodeStr(auth,noEscapeAuth,hexTable);
576576
auth+='@';
577577
}
578578

579-
varprotocol=this.protocol||'';
580-
varpathname=this.pathname||'';
581-
varhash=this.hash||'';
582-
varhost='';
583-
varquery='';
579+
letprotocol=this.protocol||'';
580+
letpathname=this.pathname||'';
581+
lethash=this.hash||'';
582+
lethost='';
583+
letquery='';
584584

585585
if(this.host){
586586
host=auth+this.host;
@@ -600,14 +600,14 @@ Url.prototype.format = function format() {
600600
query=querystring.stringify(this.query);
601601
}
602602

603-
varsearch=this.search||(query&&('?'+query))||'';
603+
letsearch=this.search||(query&&('?'+query))||'';
604604

605605
if(protocol&&protocol.charCodeAt(protocol.length-1)!==58/* : */)
606606
protocol+=':';
607607

608-
varnewPathname='';
609-
varlastPos=0;
610-
for(vari=0;i<pathname.length;++i){
608+
letnewPathname='';
609+
letlastPos=0;
610+
for(leti=0;i<pathname.length;++i){
611611
switch(pathname.charCodeAt(i)){
612612
caseCHAR_HASH:
613613
if(i-lastPos>0)
@@ -671,15 +671,15 @@ function urlResolveObject(source, relative) {
671671

672672
Url.prototype.resolveObject=functionresolveObject(relative){
673673
if(typeofrelative==='string'){
674-
varrel=newUrl();
674+
constrel=newUrl();
675675
rel.parse(relative,false,true);
676676
relative=rel;
677677
}
678678

679679
constresult=newUrl();
680680
consttkeys=Object.keys(this);
681-
for(vartk=0;tk<tkeys.length;tk++){
682-
vartkey=tkeys[tk];
681+
for(lettk=0;tk<tkeys.length;tk++){
682+
consttkey=tkeys[tk];
683683
result[tkey]=this[tkey];
684684
}
685685

@@ -696,9 +696,9 @@ Url.prototype.resolveObject = function resolveObject(relative) {
696696
// Hrefs like //foo/bar always cut to the protocol.
697697
if(relative.slashes&&!relative.protocol){
698698
// Take everything except the protocol from relative
699-
varrkeys=Object.keys(relative);
700-
for(varrk=0;rk<rkeys.length;rk++){
701-
varrkey=rkeys[rk];
699+
constrkeys=Object.keys(relative);
700+
for(letrk=0;rk<rkeys.length;rk++){
701+
constrkey=rkeys[rk];
702702
if(rkey!=='protocol')
703703
result[rkey]=relative[rkey];
704704
}
@@ -723,9 +723,9 @@ Url.prototype.resolveObject = function resolveObject(relative) {
723723
// because that's known to be hostless.
724724
// anything else is assumed to be absolute.
725725
if(!slashedProtocol.has(relative.protocol)){
726-
varkeys=Object.keys(relative);
727-
for(varv=0;v<keys.length;v++){
728-
vark=keys[v];
726+
constkeys=Object.keys(relative);
727+
for(letv=0;v<keys.length;v++){
728+
constk=keys[v];
729729
result[k]=relative[k];
730730
}
731731
result.href=result.format();
@@ -754,8 +754,8 @@ Url.prototype.resolveObject = function resolveObject(relative) {
754754
result.port=relative.port;
755755
// To support http.request
756756
if(result.pathname||result.search){
757-
varp=result.pathname||'';
758-
vars=result.search||'';
757+
constp=result.pathname||'';
758+
consts=result.search||'';
759759
result.path=p+s;
760760
}
761761
result.slashes=result.slashes||relative.slashes;
@@ -767,10 +767,10 @@ Url.prototype.resolveObject = function resolveObject(relative) {
767767
constisRelAbs=(
768768
relative.host||(relative.pathname&&relative.pathname.charAt(0)==='/')
769769
);
770-
varmustEndAbs=(isRelAbs||isSourceAbs||
770+
letmustEndAbs=(isRelAbs||isSourceAbs||
771771
(result.host&&relative.pathname));
772772
constremoveAllDots=mustEndAbs;
773-
varsrcPath=(result.pathname&&result.pathname.split('/'))||[];
773+
letsrcPath=(result.pathname&&result.pathname.split('/'))||[];
774774
constrelPath=(relative.pathname&&relative.pathname.split('/'))||[];
775775
constnoLeadingSlashes=result.protocol&&
776776
!slashedProtocol.has(result.protocol);
@@ -867,15 +867,15 @@ Url.prototype.resolveObject = function resolveObject(relative) {
867867
// If a url ENDs in . or .., then it must get a trailing slash.
868868
// however, if it ends in anything else non-slashy,
869869
// then it must NOT get a trailing slash.
870-
varlast=srcPath.slice(-1)[0];
870+
letlast=srcPath.slice(-1)[0];
871871
consthasTrailingSlash=(
872872
((result.host||relative.host||srcPath.length>1)&&
873873
(last==='.'||last==='..'))||last==='');
874874

875875
// Strip single dots, resolve double dots to parent dir
876876
// if the path tries to go above the root, `up` ends up > 0
877-
varup=0;
878-
for(vari=srcPath.length-1;i>=0;i--){
877+
letup=0;
878+
for(leti=srcPath.length-1;i>=0;i--){
879879
last=srcPath[i];
880880
if(last==='.'){
881881
spliceOne(srcPath,i);
@@ -947,8 +947,8 @@ Url.prototype.resolveObject = function resolveObject(relative) {
947947
};
948948

949949
Url.prototype.parseHost=functionparseHost(){
950-
varhost=this.host;
951-
varport=portPattern.exec(host);
950+
lethost=this.host;
951+
letport=portPattern.exec(host);
952952
if(port){
953953
port=port[0];
954954
if(port!==':'){

0 commit comments

Comments
 (0)