Browse Source

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: https://github.com/nodejs/io.js/pull/2163
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
v4.0.0-rc
Sakthipriyan Vairamani 10 years ago
parent
commit
afd7e37ee0
  1. 2
      lib/repl.js
  2. 7
      test/parallel/test-repl.js

2
lib/repl.js

@ -357,7 +357,7 @@ function REPLServer(prompt,
} }
} }
if (!skipCatchall) { if (!skipCatchall && (cmd || (!cmd && self.bufferedCommand))) {
var evalCmd = self.bufferedCommand + cmd; var evalCmd = self.bufferedCommand + cmd;
if (/^\s*\{/.test(evalCmd) && /\}\s*$/.test(evalCmd)) { if (/^\s*\{/.test(evalCmd) && /\}\s*$/.test(evalCmd)) {
// It's confusing for `{ a : 1 }` to be interpreted as a block // It's confusing for `{ a : 1 }` to be interpreted as a block

7
test/parallel/test-repl.js

@ -225,6 +225,13 @@ function error_test() {
// using REPL command "help" within a string literal should still work // using REPL command "help" within a string literal should still work
{ client: client_unix, send: '\'thefourth\\\n.help\neye\'', { client: client_unix, send: '\'thefourth\\\n.help\neye\'',
expect: /'thefourtheye'/ }, 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 },
]); ]);
} }

Loading…
Cancel
Save