Skip to content

Commit

Permalink
repl: use for...of
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Dec 31, 2019
1 parent baa3621 commit 6269129
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/repl.js
Expand Up @@ -1142,15 +1142,14 @@ function complete(line, callback) {
paths = module.paths.concat(CJSModule.globalPaths);
}

for (let i = 0; i < paths.length; i++) {
dir = path.resolve(paths[i], subdir);
for (const pathEntry of paths) {
dir = path.resolve(pathEntry, subdir);
try {
files = fs.readdirSync(dir);
} catch {
continue;
}
for (let f = 0; f < files.length; f++) {
const name = files[f];
for (const name of files) {
const ext = path.extname(name);
const base = name.slice(0, -ext.length);
if (versionedFileNamesRe.test(base) || name === '.npm') {
Expand All @@ -1170,8 +1169,8 @@ function complete(line, callback) {
} catch {
continue;
}
for (let s = 0; s < subfiles.length; s++) {
if (indexRe.test(subfiles[s])) {
for (const subfile of subfiles) {
if (indexRe.test(subfile)) {
group.push(subdir + name);
}
}
Expand Down Expand Up @@ -1295,9 +1294,9 @@ function complete(line, callback) {
}

if (memberGroups.length) {
for (let i = 0; i < memberGroups.length; i++) {
for (const memberGroup of memberGroups) {
completionGroups.push(
memberGroups[i].map((member) => `${expr}.${member}`));
memberGroup.map((member) => `${expr}.${member}`));
}
if (filter) {
filter = `${expr}.${filter}`;
Expand All @@ -1316,8 +1315,8 @@ function complete(line, callback) {
// Filter, sort (within each group), uniq and merge the completion groups.
if (completionGroups.length && filter) {
const newCompletionGroups = [];
for (let i = 0; i < completionGroups.length; i++) {
group = completionGroups[i]
for (const completionGroup of completionGroups) {
group = completionGroup
.filter((elem) => elem.indexOf(filter) === 0);
if (group.length) {
newCompletionGroups.push(group);
Expand Down Expand Up @@ -1516,8 +1515,7 @@ function defineDefaultCommands(repl) {
(max, name) => MathMax(max, name.length),
0
);
for (let n = 0; n < names.length; n++) {
const name = names[n];
for (const name of names) {
const cmd = this.commands[name];
const spaces = ' '.repeat(longestNameLength - name.length + 3);
const line = `.${name}${cmd.help ? spaces + cmd.help : ''}\n`;
Expand Down

0 comments on commit 6269129

Please sign in to comment.