Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,11 @@ REPLServer.prototype.convertToContext = function(cmd) {
return cmd;
};

function bailOnIllegalToken(parser) {
return parser._literal === null &&
!parser.blockComment &&
!parser.regExpLiteral;
}

// If the error is that we've unexpectedly ended the input,
// then let the user try to recover by adding more input.
Expand All @@ -1166,9 +1171,16 @@ function isRecoverableError(e, self) {
return true;
}

return message.startsWith('Unexpected end of input') ||
message.startsWith('Unexpected token') ||
message.startsWith('missing ) after argument list');
if (message.startsWith('Unexpected end of input') ||
message.startsWith('missing ) after argument list'))
return true;

if (message.startsWith('Unexpected token')) {
if (message.includes('ILLEGAL') && bailOnIllegalToken(self.lineParser))
return false;
else
return true;
}
}
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ function error_test() {
'undefined\n' + prompt_unix },
{ client: client_unix, send: '{ var x = 4; }',
expect: 'undefined\n' + prompt_unix },
// Illegal token is not recoverable outside string literal, RegExp literal,
// or block comment. https://github.com/nodejs/node/issues/3611
{ client: client_unix, send: 'a = 3.5e',
expect: /^SyntaxError: Unexpected token ILLEGAL/ },
]);
}

Expand Down