Skip to content

Commit

Permalink
repl: nodejs#41690 REPL gives wrong autocomplete on literals
Browse files Browse the repository at this point in the history
Fixes: nodejs#41690

PR-URL: nodejs#41883
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Mestery <[email protected]>
  • Loading branch information
meixg authored and bengl committed Feb 21, 2022
1 parent 0de611f commit c766159
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ const importRE = /\bimport\s*\(\s*['"`](([\w@./:-]+\/)?(?:[\w@./:-]*))(?![^'"`])
const requireRE = /\brequire\s*\(\s*['"`](([\w@./:-]+\/)?(?:[\w@./:-]*))(?![^'"`])$/;
const fsAutoCompleteRE = /fs(?:\.promises)?\.\s*[a-z][a-zA-Z]+\(\s*["'](.*)/;
const simpleExpressionRE =
/(?:[a-zA-Z_$](?:\w|\$)*\??\.)*[a-zA-Z_$](?:\w|\$)*\??\.?$/;
/(?:[\w$'"`[{(](?:\w|\$|['"`\]})])*\??\.)*[a-zA-Z_$](?:\w|\$)*\??\.?$/;
const versionedFileNamesRe = /-\d+\.\d+/;

function isIdentifier(str) {
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-repl-tab-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,26 @@ testMe.complete('obj.', common.mustCall(function(error, data) {
putIn.run(['.clear']);
testMe.complete('Buffer.prototype.', common.mustCall());

// Make sure repl gives correct autocomplete on literals
testMe.complete('``.a', common.mustCall((err, data) => {
assert.strictEqual(data[0].includes('``.at'), true);
}));
testMe.complete('\'\'.a', common.mustCall((err, data) => {
assert.strictEqual(data[0].includes('\'\'.at'), true);
}));
testMe.complete('"".a', common.mustCall((err, data) => {
assert.strictEqual(data[0].includes('"".at'), true);
}));
testMe.complete('("").a', common.mustCall((err, data) => {
assert.strictEqual(data[0].includes('("").at'), true);
}));
testMe.complete('[].a', common.mustCall((err, data) => {
assert.strictEqual(data[0].includes('[].at'), true);
}));
testMe.complete('{}.a', common.mustCall((err, data) => {
assert.deepStrictEqual(data[0], []);
}));

const testNonGlobal = repl.start({
input: putIn,
output: putIn,
Expand Down

0 comments on commit c766159

Please sign in to comment.