repl: add missing variable declaration

* Adds `let` to a variable declaration in a for loop
  that wasn't using anything.

* Declare the for initial expression in the for loop.

* Remove hoisted variables for loops.

PR-URL: https://github.com/nodejs/node/pull/29535
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Lucas Holmquist 2019-09-12 06:15:27 -04:00 committed by Rich Trott
parent ddd72eccfe
commit 30e919a3cf

View File

@ -1089,7 +1089,7 @@ function complete(line, callback) {
var completions; var completions;
// List of completion lists, one for each inheritance "level" // List of completion lists, one for each inheritance "level"
var completionGroups = []; var completionGroups = [];
var completeOn, i, group, c; var completeOn, group, c;
// REPL commands (e.g. ".break"). // REPL commands (e.g. ".break").
var filter; var filter;
@ -1112,7 +1112,7 @@ function complete(line, callback) {
completeOn = match[1]; completeOn = match[1];
var subdir = match[2] || ''; var subdir = match[2] || '';
filter = match[1]; filter = match[1];
var dir, files, f, name, base, ext, abs, subfiles, s, isDirectory; var dir, files, name, base, ext, abs, subfiles, isDirectory;
group = []; group = [];
let paths = []; let paths = [];
@ -1126,14 +1126,14 @@ function complete(line, callback) {
paths = module.paths.concat(CJSModule.globalPaths); paths = module.paths.concat(CJSModule.globalPaths);
} }
for (i = 0; i < paths.length; i++) { for (let i = 0; i < paths.length; i++) {
dir = path.resolve(paths[i], subdir); dir = path.resolve(paths[i], subdir);
try { try {
files = fs.readdirSync(dir); files = fs.readdirSync(dir);
} catch { } catch {
continue; continue;
} }
for (f = 0; f < files.length; f++) { for (let f = 0; f < files.length; f++) {
name = files[f]; name = files[f];
ext = path.extname(name); ext = path.extname(name);
base = name.slice(0, -ext.length); base = name.slice(0, -ext.length);
@ -1154,7 +1154,7 @@ function complete(line, callback) {
} catch { } catch {
continue; continue;
} }
for (s = 0; s < subfiles.length; s++) { for (let s = 0; s < subfiles.length; s++) {
if (indexRe.test(subfiles[s])) { if (indexRe.test(subfiles[s])) {
group.push(subdir + name); group.push(subdir + name);
} }
@ -1291,7 +1291,7 @@ function complete(line, callback) {
} }
if (memberGroups.length) { if (memberGroups.length) {
for (i = 0; i < memberGroups.length; i++) { for (let i = 0; i < memberGroups.length; i++) {
completionGroups.push( completionGroups.push(
memberGroups[i].map((member) => `${expr}.${member}`)); memberGroups[i].map((member) => `${expr}.${member}`));
} }
@ -1316,7 +1316,7 @@ function complete(line, callback) {
// Filter, sort (within each group), uniq and merge the completion groups. // Filter, sort (within each group), uniq and merge the completion groups.
if (completionGroups.length && filter) { if (completionGroups.length && filter) {
var newCompletionGroups = []; var newCompletionGroups = [];
for (i = 0; i < completionGroups.length; i++) { for (let i = 0; i < completionGroups.length; i++) {
group = completionGroups[i] group = completionGroups[i]
.filter((elem) => elem.indexOf(filter) === 0); .filter((elem) => elem.indexOf(filter) === 0);
if (group.length) { if (group.length) {
@ -1332,7 +1332,7 @@ function complete(line, callback) {
// Completion group 0 is the "closest" // Completion group 0 is the "closest"
// (least far up the inheritance chain) // (least far up the inheritance chain)
// so we put its completions last: to be closest in the REPL. // so we put its completions last: to be closest in the REPL.
for (i = 0; i < completionGroups.length; i++) { for (let i = 0; i < completionGroups.length; i++) {
group = completionGroups[i]; group = completionGroups[i];
group.sort(); group.sort();
for (var j = group.length - 1; j >= 0; j--) { for (var j = group.length - 1; j >= 0; j--) {