Skip to content
Merged
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
4 changes: 4 additions & 0 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,10 @@ function findExpressionCompleteTarget(code) {
// what we can potentially complete on, so let's re-run the function's logic on that
if (lastBodyStatement.type === 'VariableDeclaration') {
const lastDeclarationInit = lastBodyStatement.declarations.at(-1).init;
if (!lastDeclarationInit) {
// If there is no initialization we can simply return
return null;
}
const lastDeclarationInitCode = code.slice(lastDeclarationInit.start, lastDeclarationInit.end);
return findExpressionCompleteTarget(lastDeclarationInitCode);
}
Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-repl-tab-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ function prepareREPL() {
}

describe('REPL tab completion (core functionality)', () => {
it('does not break with variable declarations without an initialization', () => {
const { replServer } = prepareREPL();
replServer.complete('let a', getNoResultsFunction());
replServer.close();
});

it('does not break in an object literal', () => {
const { replServer, input } = prepareREPL();

Expand Down
Loading