Skip to content

Commit e415eb2

Browse files
kthelgasonrvagg
authored andcommitted
url: change scoping of variables with let
Also changes some `var`s to `const` as they never change. PR-URL: #4867 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 755619c commit e415eb2

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

lib/url.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
169169

170170
// find the first instance of any hostEndingChars
171171
var hostEnd = -1;
172-
for (var i = 0; i < hostEndingChars.length; i++) {
173-
var hec = rest.indexOf(hostEndingChars[i]);
172+
for (let i = 0; i < hostEndingChars.length; i++) {
173+
const hec = rest.indexOf(hostEndingChars[i]);
174174
if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
175175
hostEnd = hec;
176176
}
@@ -197,8 +197,8 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
197197

198198
// the host is the remaining to the left of the first non-host char
199199
hostEnd = -1;
200-
for (var i = 0; i < nonHostChars.length; i++) {
201-
var hec = rest.indexOf(nonHostChars[i]);
200+
for (let i = 0; i < nonHostChars.length; i++) {
201+
const hec = rest.indexOf(nonHostChars[i]);
202202
if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
203203
hostEnd = hec;
204204
}
@@ -224,12 +224,12 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
224224
// validate a little.
225225
if (!ipv6Hostname) {
226226
var hostparts = this.hostname.split(/\./);
227-
for (var i = 0, l = hostparts.length; i < l; i++) {
227+
for (let i = 0, l = hostparts.length; i < l; i++) {
228228
var part = hostparts[i];
229229
if (!part) continue;
230230
if (!part.match(hostnamePartPattern)) {
231231
var newpart = '';
232-
for (var j = 0, k = part.length; j < k; j++) {
232+
for (let j = 0, k = part.length; j < k; j++) {
233233
if (part.charCodeAt(j) > 127) {
234234
// we replace non-ASCII char with a temporary placeholder
235235
// we need this to make sure size of hostname is not
@@ -294,7 +294,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
294294
// First, make 100% sure that any "autoEscape" chars get
295295
// escaped, even if encodeURIComponent doesn't think they
296296
// need to be.
297-
for (var i = 0, l = autoEscape.length; i < l; i++) {
297+
for (let i = 0, l = autoEscape.length; i < l; i++) {
298298
var ae = autoEscape[i];
299299
if (rest.indexOf(ae) === -1)
300300
continue;
@@ -335,8 +335,8 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
335335

336336
//to support http.request
337337
if (this.pathname || this.search) {
338-
var p = this.pathname || '';
339-
var s = this.search || '';
338+
const p = this.pathname || '';
339+
const s = this.search || '';
340340
this.path = p + s;
341341
}
342342

@@ -498,7 +498,7 @@ Url.prototype.resolveObject = function(relative) {
498498
if (!relative.host &&
499499
!/^file:?$/.test(relative.protocol) &&
500500
!hostlessProtocol[relative.protocol]) {
501-
var relPath = (relative.pathname || '').split('/');
501+
const relPath = (relative.pathname || '').split('/');
502502
while (relPath.length && !(relative.host = relPath.shift()));
503503
if (!relative.host) relative.host = '';
504504
if (!relative.hostname) relative.hostname = '';
@@ -533,8 +533,8 @@ Url.prototype.resolveObject = function(relative) {
533533
var mustEndAbs = (isRelAbs || isSourceAbs ||
534534
(result.host && relative.pathname));
535535
const removeAllDots = mustEndAbs;
536-
var srcPath = result.pathname && result.pathname.split('/') || [];
537-
var relPath = relative.pathname && relative.pathname.split('/') || [];
536+
let srcPath = result.pathname && result.pathname.split('/') || [];
537+
const relPath = relative.pathname && relative.pathname.split('/') || [];
538538
const psychotic = result.protocol && !slashedProtocol[result.protocol];
539539

540540
// if the url is a non-slashed url, then relative
@@ -589,7 +589,7 @@ Url.prototype.resolveObject = function(relative) {
589589
//occasionally the auth can get stuck only in host
590590
//this especially happens in cases like
591591
//url.resolveObject('mailto:local1@domain1', 'local2@domain2')
592-
var authInHost = result.host && result.host.indexOf('@') > 0 ?
592+
const authInHost = result.host && result.host.indexOf('@') > 0 ?
593593
result.host.split('@') : false;
594594
if (authInHost) {
595595
result.auth = authInHost.shift();
@@ -632,7 +632,7 @@ Url.prototype.resolveObject = function(relative) {
632632
// strip single dots, resolve double dots to parent dir
633633
// if the path tries to go above the root, `up` ends up > 0
634634
var up = 0;
635-
for (var i = srcPath.length; i >= 0; i--) {
635+
for (let i = srcPath.length; i >= 0; i--) {
636636
last = srcPath[i];
637637
if (last === '.') {
638638
spliceOne(srcPath, i);
@@ -671,7 +671,7 @@ Url.prototype.resolveObject = function(relative) {
671671
//occasionally the auth can get stuck only in host
672672
//this especially happens in cases like
673673
//url.resolveObject('mailto:local1@domain1', 'local2@domain2')
674-
var authInHost = result.host && result.host.indexOf('@') > 0 ?
674+
const authInHost = result.host && result.host.indexOf('@') > 0 ?
675675
result.host.split('@') : false;
676676
if (authInHost) {
677677
result.auth = authInHost.shift();

0 commit comments

Comments
 (0)