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

Commit b517500

Browse files
committedJun 30, 2014
repl: fix multi-line input
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 <[email protected]>

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed
 

‎lib/repl.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,11 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
120120
displayErrors: false
121121
});
122122
} catch (e) {
123-
err = e;
124123
debug('parse error %j', code, e);
124+
if (isRecoverableError(e))
125+
err = new Recoverable(e);
126+
else
127+
err = e;
125128
}
126129

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

295298
// If error was SyntaxError and not JSON.parse error
296299
if (e) {
297-
if (isRecoverableError(e)) {
300+
if (e instanceof Recoverable) {
298301
// Start buffering data like that:
299302
// {
300303
// ... x: 1
@@ -386,15 +389,16 @@ REPLServer.prototype.resetContext = function() {
386389
};
387390

388391
REPLServer.prototype.displayPrompt = function(preserveCursor) {
389-
var prompt = this._prompt;
392+
var initial = this._prompt;
393+
var prompt = initial;
390394
if (this.bufferedCommand.length) {
391395
prompt = '...';
392396
var levelInd = new Array(this.lines.level.length).join('..');
393397
prompt += levelInd + ' ';
394-
} else {
395-
this.setPrompt(prompt);
396398
}
399+
this.setPrompt(prompt);
397400
this.prompt(preserveCursor);
401+
this.setPrompt(initial);
398402
};
399403

400404
// A stream to push an array into a REPL
@@ -940,5 +944,10 @@ REPLServer.prototype.convertToContext = function(cmd) {
940944
function isRecoverableError(e) {
941945
return e &&
942946
e.name === 'SyntaxError' &&
943-
/^Unexpected end of input/.test(e.message);
947+
/^(Unexpected end of input|Unexpected token :)/.test(e.message);
948+
}
949+
950+
function Recoverable(err) {
951+
this.err = err;
944952
}
953+
inherits(Recoverable, SyntaxError);

0 commit comments

Comments
 (0)
This repository has been archived.