Skip to content

Commit

Permalink
repl: allow multiline function call
Browse files Browse the repository at this point in the history
Currently, the repl allows multiline function declarations, strings, and
all sorts of niceties by catching the SyntaxErrors they issue and
ignoring them. However, the SyntaxError raised by multiline function
calls was not caught. This commit adds to the whitelist.

PR-URL: #3823
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
Zirak authored and rvagg committed Feb 18, 2016
1 parent c566f44 commit 98907c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,10 @@ function isRecoverableError(e, self) {
self._inTemplateLiteral = true;
return true;
}
return /^(Unexpected end of input|Unexpected token)/.test(message);

return message.startsWith('Unexpected end of input') ||
message.startsWith('Unexpected token') ||
message.startsWith('missing ) after argument list');
}
return false;
}
Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ function error_test() {
expect: prompt_multiline },
{ client: client_unix, send: '})()',
expect: '1' },
// Multiline function call
{ client: client_unix, send: 'function f(){}; f(f(1,',
expect: prompt_multiline },
{ client: client_unix, send: '2)',
expect: prompt_multiline },
{ client: client_unix, send: ')',
expect: 'undefined\n' + prompt_unix },
// npm prompt error message
{ client: client_unix, send: 'npm install foobar',
expect: expect_npm },
Expand Down

0 comments on commit 98907c7

Please sign in to comment.