@@ -222,7 +222,7 @@ function REPLServer(prompt,
222
222
eval_ = eval_ || defaultEval ;
223
223
224
224
function defaultEval ( code , context , file , cb ) {
225
- var err , result , retry = false ;
225
+ var err , result , retry = false , input = code , wrappedErr ;
226
226
// first, create the Script object to check the syntax
227
227
while ( true ) {
228
228
try {
@@ -240,14 +240,23 @@ function REPLServer(prompt,
240
240
debug ( 'parse error %j' , code , e ) ;
241
241
if ( self . replMode === exports . REPL_MODE_MAGIC &&
242
242
e . message === BLOCK_SCOPED_ERROR &&
243
- ! retry ) {
244
- retry = true ;
243
+ ! retry || self . wrappedCmd ) {
244
+ if ( self . wrappedCmd ) {
245
+ self . wrappedCmd = false ;
246
+ // unwrap and try again
247
+ code = `${ input . substring ( 1 , input . length - 2 ) } \n` ;
248
+ wrappedErr = e ;
249
+ } else {
250
+ retry = true ;
251
+ }
245
252
continue ;
246
253
}
247
- if ( isRecoverableError ( e , self ) )
248
- err = new Recoverable ( e ) ;
254
+ // preserve original error for wrapped command
255
+ const error = wrappedErr || e ;
256
+ if ( isRecoverableError ( error , self ) )
257
+ err = new Recoverable ( error ) ;
249
258
else
250
- err = e ;
259
+ err = error ;
251
260
}
252
261
break ;
253
262
}
@@ -420,6 +429,7 @@ function REPLServer(prompt,
420
429
// to wrap it in parentheses, so that it will be interpreted as
421
430
// an expression.
422
431
evalCmd = '(' + evalCmd + ')\n' ;
432
+ self . wrappedCmd = true ;
423
433
} else {
424
434
// otherwise we just append a \n so that it will be either
425
435
// terminated, or continued onto the next expression if it's an
@@ -437,6 +447,7 @@ function REPLServer(prompt,
437
447
debug ( 'finish' , e , ret ) ;
438
448
self . memory ( cmd ) ;
439
449
450
+ self . wrappedCmd = false ;
440
451
if ( e && ! self . bufferedCommand && cmd . trim ( ) . match ( / ^ n p m / ) ) {
441
452
self . outputStream . write ( 'npm should be run outside of the ' +
442
453
'node repl, in your normal shell.\n' +
0 commit comments