Browse Source

repl: allow leading period in multiline input

When writing multiline input, one can't chain function calls as if the
lines begin with a period, since those are treated as REPL commands.

Before:

    > ([0, 1, 2]
    ... .map(x => x + 1))
    Invalid REPL keyword

After:

    > ([0, 1, 2]
    ... .map(x => x + 1))
    [ 1, 2, 3 ]

PR-URL: https://github.com/nodejs/node/pull/3835
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
v5.x
Zirak 9 years ago
committed by Rod Vagg
parent
commit
0869ef3c55
  1. 2
      lib/repl.js
  2. 5
      test/parallel/test-repl.js

2
lib/repl.js

@ -391,7 +391,7 @@ function REPLServer(prompt,
var rest = matches && matches[2]; var rest = matches && matches[2];
if (self.parseREPLKeyword(keyword, rest) === true) { if (self.parseREPLKeyword(keyword, rest) === true) {
return; return;
} else { } else if (!self.bufferedCommand) {
self.outputStream.write('Invalid REPL keyword\n'); self.outputStream.write('Invalid REPL keyword\n');
skipCatchall = true; skipCatchall = true;
} }

5
test/parallel/test-repl.js

@ -117,6 +117,11 @@ function error_test() {
expect: prompt_multiline }, expect: prompt_multiline },
{ client: client_unix, send: '+ ".2"}`', { client: client_unix, send: '+ ".2"}`',
expect: `'io.js 1.0.2'\n${prompt_unix}` }, expect: `'io.js 1.0.2'\n${prompt_unix}` },
// Dot prefix in multiline commands aren't treated as commands
{ client: client_unix, send: '("a"',
expect: prompt_multiline },
{ client: client_unix, send: '.charAt(0))',
expect: `'a'\n${prompt_unix}` },
// Floating point numbers are not interpreted as REPL commands. // Floating point numbers are not interpreted as REPL commands.
{ client: client_unix, send: '.1234', { client: client_unix, send: '.1234',
expect: '0.1234' }, expect: '0.1234' },

Loading…
Cancel
Save