Skip to content

Commit

Permalink
repl: better empty line handling
Browse files Browse the repository at this point in the history
In REPL, if we try to evaluate an empty line, we get `undefined`.

    > process.version
    'v2.3.4'
    >
    undefined
    >
    undefined
    >

This patch prevents `undefined` from printing if the string is empty.

    > process.version
    'v2.3.5-pre'
    >
    >
    >

PR-URL: #2163
Reviewed-By: Jeremiah Senkpiel <[email protected]>
  • Loading branch information
thefourtheye committed Jul 24, 2015
1 parent 81ea52a commit afd7e37
Show file tree
Hide file tree
Showing 2 changed files with 8 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 @@ -357,7 +357,7 @@ function REPLServer(prompt,
}
}

if (!skipCatchall) {
if (!skipCatchall && (cmd || (!cmd && self.bufferedCommand))) {
var evalCmd = self.bufferedCommand + cmd;
if (/^\s*\{/.test(evalCmd) && /\}\s*$/.test(evalCmd)) {
// It's confusing for `{ a : 1 }` to be interpreted as a block
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 @@ -225,6 +225,13 @@ function error_test() {
// using REPL command "help" within a string literal should still work
{ client: client_unix, send: '\'thefourth\\\n.help\neye\'',
expect: /'thefourtheye'/ },
// empty lines in the REPL should be allowed
{ client: client_unix, send: '\n\r\n\r\n',
expect: prompt_unix + prompt_unix + prompt_unix },
// empty lines in the string literals should not affect the string
{ client: client_unix, send: '\'the\\\n\\\nfourtheye\'\n',
expect: prompt_multiline + prompt_multiline +
'\'thefourtheye\'\n' + prompt_unix },
]);
}

Expand Down

0 comments on commit afd7e37

Please sign in to comment.