@@ -426,59 +426,66 @@ function REPLServer(prompt,
426
426
( { processTopLevelAwait } = require ( 'internal/repl/await' ) ) ;
427
427
}
428
428
429
- const potentialWrappedCode = processTopLevelAwait ( code ) ;
430
- if ( potentialWrappedCode !== null ) {
431
- code = potentialWrappedCode ;
432
- wrappedCmd = true ;
433
- awaitPromise = true ;
429
+ try {
430
+ const potentialWrappedCode = processTopLevelAwait ( code ) ;
431
+ if ( potentialWrappedCode !== null ) {
432
+ code = potentialWrappedCode ;
433
+ wrappedCmd = true ;
434
+ awaitPromise = true ;
435
+ }
436
+ } catch ( e ) {
437
+ decorateErrorStack ( e ) ;
438
+ err = e ;
434
439
}
435
440
}
436
441
437
442
// First, create the Script object to check the syntax
438
443
if ( code === '\n' )
439
444
return cb ( null ) ;
440
445
441
- let parentURL ;
442
- try {
443
- const { pathToFileURL } = require ( 'url' ) ;
444
- // Adding `/repl` prevents dynamic imports from loading relative
445
- // to the parent of `process.cwd()`.
446
- parentURL = pathToFileURL ( path . join ( process . cwd ( ) , 'repl' ) ) . href ;
447
- } catch {
448
- }
449
- while ( true ) {
446
+ if ( err === null ) {
447
+ let parentURL ;
450
448
try {
451
- if ( self . replMode === module . exports . REPL_MODE_STRICT &&
452
- ! RegExpPrototypeTest ( / ^ \s * $ / , code ) ) {
453
- // "void 0" keeps the repl from returning "use strict" as the result
454
- // value for statements and declarations that don't return a value.
455
- code = `'use strict'; void 0;\n${ code } ` ;
456
- }
457
- script = vm . createScript ( code , {
458
- filename : file ,
459
- displayErrors : true ,
460
- importModuleDynamically : async ( specifier ) => {
461
- return asyncESM . ESMLoader . import ( specifier , parentURL ) ;
449
+ const { pathToFileURL } = require ( 'url' ) ;
450
+ // Adding `/repl` prevents dynamic imports from loading relative
451
+ // to the parent of `process.cwd()`.
452
+ parentURL = pathToFileURL ( path . join ( process . cwd ( ) , 'repl' ) ) . href ;
453
+ } catch {
454
+ }
455
+ while ( true ) {
456
+ try {
457
+ if ( self . replMode === module . exports . REPL_MODE_STRICT &&
458
+ ! RegExpPrototypeTest ( / ^ \s * $ / , code ) ) {
459
+ // "void 0" keeps the repl from returning "use strict" as the result
460
+ // value for statements and declarations that don't return a value.
461
+ code = `'use strict'; void 0;\n${ code } ` ;
462
462
}
463
- } ) ;
464
- } catch ( e ) {
465
- debug ( 'parse error %j' , code , e ) ;
466
- if ( wrappedCmd ) {
467
- // Unwrap and try again
468
- wrappedCmd = false ;
469
- awaitPromise = false ;
470
- code = input ;
471
- wrappedErr = e ;
472
- continue ;
463
+ script = vm . createScript ( code , {
464
+ filename : file ,
465
+ displayErrors : true ,
466
+ importModuleDynamically : async ( specifier ) => {
467
+ return asyncESM . ESMLoader . import ( specifier , parentURL ) ;
468
+ }
469
+ } ) ;
470
+ } catch ( e ) {
471
+ debug ( 'parse error %j' , code , e ) ;
472
+ if ( wrappedCmd ) {
473
+ // Unwrap and try again
474
+ wrappedCmd = false ;
475
+ awaitPromise = false ;
476
+ code = input ;
477
+ wrappedErr = e ;
478
+ continue ;
479
+ }
480
+ // Preserve original error for wrapped command
481
+ const error = wrappedErr || e ;
482
+ if ( isRecoverableError ( error , code ) )
483
+ err = new Recoverable ( error ) ;
484
+ else
485
+ err = error ;
473
486
}
474
- // Preserve original error for wrapped command
475
- const error = wrappedErr || e ;
476
- if ( isRecoverableError ( error , code ) )
477
- err = new Recoverable ( error ) ;
478
- else
479
- err = error ;
487
+ break ;
480
488
}
481
- break ;
482
489
}
483
490
484
491
// This will set the values from `savedRegExMatches` to corresponding
0 commit comments