Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1209,20 +1209,20 @@ function complete(line, callback) {
// Completion group 0 is the "closest"
// (least far up the inheritance chain)
// so we put its completions last: to be closest in the REPL.
for (i = completionGroups.length - 1; i >= 0; i--) {
for (i = 0; i < completionGroups.length; i++) {
group = completionGroups[i];
group.sort();
for (var j = 0; j < group.length; j++) {
for (var j = group.length - 1; j >= 0; j--) {
c = group[j];
if (!hasOwnProperty(uniq, c)) {
completions.push(c);
completions.unshift(c);
uniq[c] = true;
}
}
completions.push(''); // Separator btwn groups
completions.unshift(''); // Separator btwn groups
}
while (completions.length && completions[completions.length - 1] === '') {
completions.pop();
while (completions.length && completions[0] === '') {
completions.shift();
}
}

Expand Down
19 changes: 18 additions & 1 deletion test/parallel/test-repl-tab-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ putIn.run([
' one:1',
'};'
]);
testMe.complete('inner.o', getNoResultsFunction());
// See: https://github.com/nodejs/node/issues/21586
// testMe.complete('inner.o', getNoResultsFunction());
testMe.complete('inner.o', common.mustCall(function(error, data) {
}));

putIn.run(['.clear']);

Expand Down Expand Up @@ -206,6 +209,20 @@ testMe.complete('toSt', common.mustCall(function(error, data) {
assert.deepStrictEqual(data, [['toString'], 'toSt']);
}));

// own properties should shadow properties on the prototype
putIn.run(['.clear']);
putIn.run([
'var x = Object.create(null);',
'x.a = 1;',
'x.b = 2;',
'var y = Object.create(x);',
'y.a = 3;',
'y.c = 4;'
]);
testMe.complete('y.', common.mustCall(function(error, data) {
assert.deepStrictEqual(data, [['y.b', '', 'y.a', 'y.c'], 'y.']);
}));

// Tab complete provides built in libs for require()
putIn.run(['.clear']);

Expand Down