GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — repl: fix repl crashing on variable declarations without init · nodejs/node@467dbd3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • repl.js
  • test/parallel
    • test-repl-tab-complete.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,10 @@ function findExpressionCompleteTarget(code) {
17351735
// what we can potentially complete on, so let's re-run the function's logic on that
17361736
if (lastBodyStatement.type === 'VariableDeclaration') {
17371737
const lastDeclarationInit = lastBodyStatement.declarations.at(-1).init;
1738+
if (!lastDeclarationInit) {
1739+
// If there is no initialization we can simply return
1740+
return null;
1741+
}
17381742
const lastDeclarationInitCode = code.slice(lastDeclarationInit.start, lastDeclarationInit.end);
17391743
return findExpressionCompleteTarget(lastDeclarationInitCode);
17401744
}
Collapse file

‎test/parallel/test-repl-tab-complete.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-tab-complete.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ function prepareREPL() {
5050
}
5151

5252
describe('REPL tab completion (core functionality)', () => {
53+
it('does not break with variable declarations without an initialization', () => {
54+
const { replServer } = prepareREPL();
55+
replServer.complete('let a', getNoResultsFunction());
56+
replServer.close();
57+
});
58+
5359
it('does not break in an object literal', () => {
5460
const { replServer, input } = prepareREPL();
5561

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.