diff --git a/lib/repl.js b/lib/repl.js index 44aed66a6d..3a96eea136 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -647,7 +647,7 @@ ArrayStream.prototype.write = function() {}; const requireRE = /\brequire\s*\(['"](([\w\.\/-]+\/)?([\w\.\/-]*))/; const simpleExpressionRE = - /(([a-zA-Z_$](?:\w|\$)*)\.)*([a-zA-Z_$](?:\w|\$)*)\.?$/; + /^\s*(([a-zA-Z_$](?:\w|\$)*)\.)*([a-zA-Z_$](?:\w|\$)*)\.?$/; function intFilter(item) { // filters out anything not starting with A-Z, a-z, $ or _ diff --git a/test/parallel/test-repl-tab-complete.js b/test/parallel/test-repl-tab-complete.js index ee9cce312e..d52f0068ec 100644 --- a/test/parallel/test-repl-tab-complete.js +++ b/test/parallel/test-repl-tab-complete.js @@ -249,3 +249,11 @@ testMe.complete('obj.', common.mustCall(function(error, data) { assert.strictEqual(data[0].indexOf('obj.1a'), -1); assert.notStrictEqual(data[0].indexOf('obj.a'), -1); })); + +// Don't try to complete results of non-simple expressions +putIn.run(['.clear']); +putIn.run(['function a() {}']); + +testMe.complete('a().b.', common.mustCall((error, data) => { + assert.deepEqual(data, [[], undefined]); +}));