@@ -220,7 +220,7 @@ function REPLServer(prompt,
220220 eval_ = eval_ || defaultEval ;
221221
222222 function defaultEval ( code , context , file , cb ) {
223- var err , result , retry = false ;
223+ var err , result , retry = false , input = code , wrappedErr ;
224224 // first, create the Script object to check the syntax
225225 while ( true ) {
226226 try {
@@ -238,14 +238,23 @@ function REPLServer(prompt,
238238 debug ( 'parse error %j' , code , e ) ;
239239 if ( self . replMode === exports . REPL_MODE_MAGIC &&
240240 e . message === BLOCK_SCOPED_ERROR &&
241- ! retry ) {
242- retry = true ;
241+ ! retry || self . wrappedCmd ) {
242+ if ( self . wrappedCmd ) {
243+ self . wrappedCmd = false ;
244+ // unwrap and try again
245+ code = `${ input . substring ( 1 , input . length - 2 ) } \n` ;
246+ wrappedErr = e ;
247+ } else {
248+ retry = true ;
249+ }
243250 continue ;
244251 }
245- if ( isRecoverableError ( e , self ) )
246- err = new Recoverable ( e ) ;
252+ // preserve original error for wrapped command
253+ const error = wrappedErr || e ;
254+ if ( isRecoverableError ( error , self ) )
255+ err = new Recoverable ( error ) ;
247256 else
248- err = e ;
257+ err = error ;
249258 }
250259 break ;
251260 }
@@ -418,6 +427,7 @@ function REPLServer(prompt,
418427 // to wrap it in parentheses, so that it will be interpreted as
419428 // an expression.
420429 evalCmd = '(' + evalCmd + ')\n' ;
430+ self . wrappedCmd = true ;
421431 } else {
422432 // otherwise we just append a \n so that it will be either
423433 // terminated, or continued onto the next expression if it's an
@@ -435,6 +445,7 @@ function REPLServer(prompt,
435445 debug ( 'finish' , e , ret ) ;
436446 self . memory ( cmd ) ;
437447
448+ self . wrappedCmd = false ;
438449 if ( e && ! self . bufferedCommand && cmd . trim ( ) . match ( / ^ n p m / ) ) {
439450 self . outputStream . write ( 'npm should be run outside of the ' +
440451 'node repl, in your normal shell.\n' +
0 commit comments