Browse Source

repl: allow multiline function call

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: https://github.com/nodejs/node/pull/3823
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
v5.x
Zirak 9 years ago
committed by Rod Vagg
parent
commit
98907c716b
  1. 5
      lib/repl.js
  2. 7
      test/parallel/test-repl.js

5
lib/repl.js

@ -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;
}

7
test/parallel/test-repl.js

@ -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 },

Loading…
Cancel
Save