Skip to content

Commit afd7e37

Browse files
committed
repl: better empty line handling
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]>
1 parent 81ea52a commit afd7e37

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/repl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ function REPLServer(prompt,
357357
}
358358
}
359359

360-
if (!skipCatchall) {
360+
if (!skipCatchall && (cmd || (!cmd && self.bufferedCommand))) {
361361
var evalCmd = self.bufferedCommand + cmd;
362362
if (/^\s*\{/.test(evalCmd) && /\}\s*$/.test(evalCmd)) {
363363
// It's confusing for `{ a : 1 }` to be interpreted as a block

test/parallel/test-repl.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ function error_test() {
225225
// using REPL command "help" within a string literal should still work
226226
{ client: client_unix, send: '\'thefourth\\\n.help\neye\'',
227227
expect: /'thefourtheye'/ },
228+
// empty lines in the REPL should be allowed
229+
{ client: client_unix, send: '\n\r\n\r\n',
230+
expect: prompt_unix + prompt_unix + prompt_unix },
231+
// empty lines in the string literals should not affect the string
232+
{ client: client_unix, send: '\'the\\\n\\\nfourtheye\'\n',
233+
expect: prompt_multiline + prompt_multiline +
234+
'\'thefourtheye\'\n' + prompt_unix },
228235
]);
229236
}
230237

0 commit comments

Comments
 (0)