mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
repl: fix repl crashing on variable declarations without init
PR-URL: https://github.com/nodejs/node/pull/59032 Fixes: https://github.com/nodejs/node/issues/59029 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
9d02960149
commit
467dbd31e6
2 files changed
+10
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in new issue
Block a user