Skip to content

Commit 6269129

Browse files
committed
repl: use for...of
1 parent baa3621 commit 6269129

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

lib/repl.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -1142,15 +1142,14 @@ function complete(line, callback) {
11421142
paths = module.paths.concat(CJSModule.globalPaths);
11431143
}
11441144

1145-
for (let i = 0; i < paths.length; i++) {
1146-
dir = path.resolve(paths[i], subdir);
1145+
for (const pathEntry of paths) {
1146+
dir = path.resolve(pathEntry, subdir);
11471147
try {
11481148
files = fs.readdirSync(dir);
11491149
} catch {
11501150
continue;
11511151
}
1152-
for (let f = 0; f < files.length; f++) {
1153-
const name = files[f];
1152+
for (const name of files) {
11541153
const ext = path.extname(name);
11551154
const base = name.slice(0, -ext.length);
11561155
if (versionedFileNamesRe.test(base) || name === '.npm') {
@@ -1170,8 +1169,8 @@ function complete(line, callback) {
11701169
} catch {
11711170
continue;
11721171
}
1173-
for (let s = 0; s < subfiles.length; s++) {
1174-
if (indexRe.test(subfiles[s])) {
1172+
for (const subfile of subfiles) {
1173+
if (indexRe.test(subfile)) {
11751174
group.push(subdir + name);
11761175
}
11771176
}
@@ -1295,9 +1294,9 @@ function complete(line, callback) {
12951294
}
12961295

12971296
if (memberGroups.length) {
1298-
for (let i = 0; i < memberGroups.length; i++) {
1297+
for (const memberGroup of memberGroups) {
12991298
completionGroups.push(
1300-
memberGroups[i].map((member) => `${expr}.${member}`));
1299+
memberGroup.map((member) => `${expr}.${member}`));
13011300
}
13021301
if (filter) {
13031302
filter = `${expr}.${filter}`;
@@ -1316,8 +1315,8 @@ function complete(line, callback) {
13161315
// Filter, sort (within each group), uniq and merge the completion groups.
13171316
if (completionGroups.length && filter) {
13181317
const newCompletionGroups = [];
1319-
for (let i = 0; i < completionGroups.length; i++) {
1320-
group = completionGroups[i]
1318+
for (const completionGroup of completionGroups) {
1319+
group = completionGroup
13211320
.filter((elem) => elem.indexOf(filter) === 0);
13221321
if (group.length) {
13231322
newCompletionGroups.push(group);
@@ -1516,8 +1515,7 @@ function defineDefaultCommands(repl) {
15161515
(max, name) => MathMax(max, name.length),
15171516
0
15181517
);
1519-
for (let n = 0; n < names.length; n++) {
1520-
const name = names[n];
1518+
for (const name of names) {
15211519
const cmd = this.commands[name];
15221520
const spaces = ' '.repeat(longestNameLength - name.length + 3);
15231521
const line = `.${name}${cmd.help ? spaces + cmd.help : ''}\n`;

0 commit comments

Comments
 (0)