Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: use for...of #31050

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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