From 38b13e3c2c0bbb0014294504ccfed396f5a8a721 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 29 Jan 2016 20:34:13 -0800 Subject: [PATCH 1/2] lib: scope loop variables Refactor instances in `lib` where a loop variable is redeclared in the same scope with `var`. In these cases, `let` can be used to scope the variable declarations more precisely. --- lib/path.js | 8 ++++---- lib/util.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/path.js b/lib/path.js index 66a3fa448f30eb..ab86195696eb22 100644 --- a/lib/path.js +++ b/lib/path.js @@ -270,7 +270,7 @@ win32.relative = function(from, to) { var length = Math.min(lowerFromParts.length, lowerToParts.length); var samePartsLength = length; - for (var i = 0; i < length; i++) { + for (let i = 0; i < length; i++) { if (lowerFromParts[i] !== lowerToParts[i]) { samePartsLength = i; break; @@ -282,7 +282,7 @@ win32.relative = function(from, to) { } var outputParts = []; - for (var i = samePartsLength; i < lowerFromParts.length; i++) { + for (let i = samePartsLength; i < lowerFromParts.length; i++) { outputParts.push('..'); } @@ -495,7 +495,7 @@ posix.relative = function(from, to) { var length = Math.min(fromParts.length, toParts.length); var samePartsLength = length; - for (var i = 0; i < length; i++) { + for (let i = 0; i < length; i++) { if (fromParts[i] !== toParts[i]) { samePartsLength = i; break; @@ -503,7 +503,7 @@ posix.relative = function(from, to) { } var outputParts = []; - for (var i = samePartsLength; i < fromParts.length; i++) { + for (let i = samePartsLength; i < fromParts.length; i++) { outputParts.push('..'); } diff --git a/lib/util.js b/lib/util.js index 50cc5bc5b4b25d..44012cf90ec4c2 100644 --- a/lib/util.js +++ b/lib/util.js @@ -13,7 +13,7 @@ const formatRegExp = /%[sdj%]/g; exports.format = function(f) { if (typeof f !== 'string') { var objects = []; - for (var i = 0; i < arguments.length; i++) { + for (let i = 0; i < arguments.length; i++) { objects.push(inspect(arguments[i])); } return objects.join(' '); From b49117c713f8e9b779602f56b3a875a3b101def3 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 30 Jan 2016 14:31:10 -0800 Subject: [PATCH 2/2] fixup --- lib/path.js | 8 ++++---- lib/util.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/path.js b/lib/path.js index ab86195696eb22..a2162cae7c9c97 100644 --- a/lib/path.js +++ b/lib/path.js @@ -270,7 +270,7 @@ win32.relative = function(from, to) { var length = Math.min(lowerFromParts.length, lowerToParts.length); var samePartsLength = length; - for (let i = 0; i < length; i++) { + for (var i = 0; i < length; i++) { if (lowerFromParts[i] !== lowerToParts[i]) { samePartsLength = i; break; @@ -282,7 +282,7 @@ win32.relative = function(from, to) { } var outputParts = []; - for (let i = samePartsLength; i < lowerFromParts.length; i++) { + for (var j = samePartsLength; j < lowerFromParts.length; j++) { outputParts.push('..'); } @@ -495,7 +495,7 @@ posix.relative = function(from, to) { var length = Math.min(fromParts.length, toParts.length); var samePartsLength = length; - for (let i = 0; i < length; i++) { + for (var i = 0; i < length; i++) { if (fromParts[i] !== toParts[i]) { samePartsLength = i; break; @@ -503,7 +503,7 @@ posix.relative = function(from, to) { } var outputParts = []; - for (let i = samePartsLength; i < fromParts.length; i++) { + for (var j = samePartsLength; j < fromParts.length; j++) { outputParts.push('..'); } diff --git a/lib/util.js b/lib/util.js index 44012cf90ec4c2..2908d4ece9192f 100644 --- a/lib/util.js +++ b/lib/util.js @@ -13,8 +13,8 @@ const formatRegExp = /%[sdj%]/g; exports.format = function(f) { if (typeof f !== 'string') { var objects = []; - for (let i = 0; i < arguments.length; i++) { - objects.push(inspect(arguments[i])); + for (var index = 0; index < arguments.length; index++) { + objects.push(inspect(arguments[index])); } return objects.join(' '); }