@@ -426,59 +426,66 @@ function REPLServer(prompt,
426426 ( { processTopLevelAwait } = require ( 'internal/repl/await' ) ) ;
427427 }
428428
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 ;
434439 }
435440 }
436441
437442 // First, create the Script object to check the syntax
438443 if ( code === '\n' )
439444 return cb ( null ) ;
440445
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 ;
450448 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 } ` ;
462462 }
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 ;
473486 }
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 ;
480488 }
481- break ;
482489 }
483490
484491 // This will set the values from `savedRegExMatches` to corresponding
0 commit comments