@ -87,6 +87,8 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
self . useGlobal = ! ! useGlobal ;
self . ignoreUndefined = ! ! ignoreUndefined ;
self . _ inTemplateLiteral = false ;
// just for backwards compat, see github.com/joyent/node/pull/7127
self . rli = this ;
@ -102,7 +104,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
} ) ;
} catch ( e ) {
debug ( 'parse error %j' , code , e ) ;
if ( isRecoverableError ( e ) )
if ( isRecoverableError ( e , self ) )
err = new Recoverable ( e ) ;
else
err = e ;
@ -226,7 +228,13 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
debug ( 'line %j' , cmd ) ;
sawSIGINT = false ;
var skipCatchall = false ;
cmd = trimWhitespace ( cmd ) ;
// leading whitespaces in template literals should not be trimmed.
if ( self . _ inTemplateLiteral ) {
self . _ inTemplateLiteral = false ;
} else {
cmd = trimWhitespace ( cmd ) ;
}
// Check to see if a REPL keyword was used. If it returns true,
// display next prompt and return.
@ -928,10 +936,17 @@ REPLServer.prototype.convertToContext = function(cmd) {
// If the error is that we've unexpectedly ended the input,
// then let the user try to recover by adding more input.
function isRecoverableError ( e ) {
return e &&
e . name === 'SyntaxError' &&
/^(Unexpected end of input|Unexpected token :)/ . test ( e . message ) ;
function isRecoverableError ( e , self ) {
if ( e && e . name === 'SyntaxError' ) {
var message = e . message ;
if ( message === 'Unterminated template literal' ||
message === 'Missing } in template expression' ) {
self . _ inTemplateLiteral = true ;
return true ;
}
return /^(Unexpected end of input|Unexpected token :)/ . test ( message ) ;
}
return false ;
}
function Recoverable ( err ) {