Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
repl: fix multi-line input
Browse files Browse the repository at this point in the history
The refactor in 3ae0b17 broke the multiline input's visual appearence.
While actually switching to this mode, the `...` prefix is not
displayed.

Additionally, account only SyntaxErrors that are happening at the parse
time, everything else should not be switching repl to the multiline
mode.

Signed-off-by: Fedor Indutny <fedor@indutny.com>
  • Loading branch information
indutny committed Jun 30, 2014
1 parent 7fa4a96 commit b517500
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
displayErrors: false
});
} catch (e) {
err = e;
debug('parse error %j', code, e);
if (isRecoverableError(e))
err = new Recoverable(e);
else
err = e;
}

if (!err) {
Expand Down Expand Up @@ -294,7 +297,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {

// If error was SyntaxError and not JSON.parse error
if (e) {
if (isRecoverableError(e)) {
if (e instanceof Recoverable) {
// Start buffering data like that:
// {
// ... x: 1
Expand Down Expand Up @@ -386,15 +389,16 @@ REPLServer.prototype.resetContext = function() {
};

REPLServer.prototype.displayPrompt = function(preserveCursor) {
var prompt = this._prompt;
var initial = this._prompt;
var prompt = initial;
if (this.bufferedCommand.length) {
prompt = '...';
var levelInd = new Array(this.lines.level.length).join('..');
prompt += levelInd + ' ';
} else {
this.setPrompt(prompt);
}
this.setPrompt(prompt);
this.prompt(preserveCursor);
this.setPrompt(initial);
};

// A stream to push an array into a REPL
Expand Down Expand Up @@ -940,5 +944,10 @@ REPLServer.prototype.convertToContext = function(cmd) {
function isRecoverableError(e) {
return e &&
e.name === 'SyntaxError' &&
/^Unexpected end of input/.test(e.message);
/^(Unexpected end of input|Unexpected token :)/.test(e.message);
}

function Recoverable(err) {
this.err = err;
}
inherits(Recoverable, SyntaxError);

0 comments on commit b517500

Please sign in to comment.