@@ -498,7 +498,19 @@ function REPLServer(prompt,
498
498
}
499
499
500
500
var evalCmd = self . bufferedCommand + cmd ;
501
- evalCmd = preprocess ( evalCmd ) ;
501
+ if ( / ^ \s * \{ / . test ( evalCmd ) && / \} \s * $ / . test ( evalCmd ) ) {
502
+ // It's confusing for `{ a : 1 }` to be interpreted as a block
503
+ // statement rather than an object literal. So, we first try
504
+ // to wrap it in parentheses, so that it will be interpreted as
505
+ // an expression.
506
+ evalCmd = '(' + evalCmd + ')\n' ;
507
+ self . wrappedCmd = true ;
508
+ } else {
509
+ // otherwise we just append a \n so that it will be either
510
+ // terminated, or continued onto the next expression if it's an
511
+ // unexpected end of input.
512
+ evalCmd = evalCmd + '\n' ;
513
+ }
502
514
503
515
debug ( 'eval %j' , evalCmd ) ;
504
516
self . eval ( evalCmd , self . context , 'repl' , finish ) ;
@@ -555,26 +567,6 @@ function REPLServer(prompt,
555
567
// Display prompt again
556
568
self . displayPrompt ( ) ;
557
569
}
558
-
559
- function preprocess ( code ) {
560
- let cmd = code ;
561
- if ( / ^ \s * \{ / . test ( cmd ) && / \} \s * $ / . test ( cmd ) ) {
562
- // It's confusing for `{ a : 1 }` to be interpreted as a block
563
- // statement rather than an object literal. So, we first try
564
- // to wrap it in parentheses, so that it will be interpreted as
565
- // an expression.
566
- cmd = `(${ cmd } )` ;
567
- self . wrappedCmd = true ;
568
- } else {
569
- // Mitigate https://github.com/nodejs/node/issues/548
570
- cmd = cmd . replace ( / ^ \s * f u n c t i o n \s + ( [ ^ ( ] + ) / ,
571
- ( _ , name ) => `var ${ name } = function ${ name } ` ) ;
572
- }
573
- // Append a \n so that it will be either
574
- // terminated, or continued onto the next expression if it's an
575
- // unexpected end of input.
576
- return `${ cmd } \n` ;
577
- }
578
570
} ) ;
579
571
580
572
self . on ( 'SIGCONT' , function ( ) {
0 commit comments