Skip to content

Commit

Permalink
repl: allow leading period in multiline input
Browse files Browse the repository at this point in the history
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: #3835
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
  • Loading branch information
Zirak authored and rvagg committed Dec 5, 2015
1 parent 2b5b127 commit 0869ef3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ function REPLServer(prompt,
var rest = matches && matches[2];
if (self.parseREPLKeyword(keyword, rest) === true) {
return;
} else {
} else if (!self.bufferedCommand) {
self.outputStream.write('Invalid REPL keyword\n');
skipCatchall = true;
}
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ function error_test() {
expect: prompt_multiline },
{ client: client_unix, send: '+ ".2"}`',
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.
{ client: client_unix, send: '.1234',
expect: '0.1234' },
Expand Down

0 comments on commit 0869ef3

Please sign in to comment.