@@ -100,9 +100,11 @@ const {
100100 overrideStackTrace,
101101} = require ( 'internal/errors' ) ;
102102const { sendInspectorCommand } = require ( 'internal/util/inspector' ) ;
103- const experimentalREPLAwait = require ( 'internal/options' ) . getOptionValue (
103+ const { getOptionValue } = require ( 'internal/options' ) ;
104+ const experimentalREPLAwait = getOptionValue (
104105 '--experimental-repl-await'
105106) ;
107+ const pendingDeprecation = getOptionValue ( '--pending-deprecation' ) ;
106108const {
107109 REPL_MODE_SLOPPY ,
108110 REPL_MODE_STRICT ,
@@ -220,8 +222,39 @@ function REPLServer(prompt,
220222 const preview = options . terminal &&
221223 ( options . preview !== undefined ? ! ! options . preview : ! eval_ ) ;
222224
223- this . inputStream = options . input ;
224- this . outputStream = options . output ;
225+ ObjectDefineProperty ( this , 'inputStream' , {
226+ get : pendingDeprecation ?
227+ deprecate ( ( ) => this . input ,
228+ 'repl.inputStream and repl.outputStream is deprecated. ' +
229+ 'Use repl.input and repl.output instead' ,
230+ 'DEP0XXX' ) :
231+ ( ) => this . input ,
232+ set : pendingDeprecation ?
233+ deprecate ( ( val ) => this . input = val ,
234+ 'repl.inputStream and repl.outputStream is deprecated. ' +
235+ 'Use repl.input and repl.output instead' ,
236+ 'DEP0XXX' ) :
237+ ( val ) => this . input = val ,
238+ enumerable : false ,
239+ configurable : true
240+ } ) ;
241+ ObjectDefineProperty ( this , 'outputStream' , {
242+ get : pendingDeprecation ?
243+ deprecate ( ( ) => this . output ,
244+ 'repl.inputStream and repl.outputStream is deprecated. ' +
245+ 'Use repl.input and repl.output instead' ,
246+ 'DEP0XXX' ) :
247+ ( ) => this . output ,
248+ set : pendingDeprecation ?
249+ deprecate ( ( val ) => this . output = val ,
250+ 'repl.inputStream and repl.outputStream is deprecated. ' +
251+ 'Use repl.input and repl.output instead' ,
252+ 'DEP0XXX' ) :
253+ ( val ) => this . output = val ,
254+ enumerable : false ,
255+ configurable : true
256+ } ) ;
257+
225258 this . useColors = ! ! options . useColors ;
226259 this . _domain = options . domain || domain . create ( ) ;
227260 this . useGlobal = ! ! useGlobal ;
@@ -596,16 +629,13 @@ function REPLServer(prompt,
596629 }
597630 // Normalize line endings.
598631 errStack += errStack . endsWith ( '\n' ) ? '' : '\n' ;
599- self . outputStream . write ( errStack ) ;
632+ self . output . write ( errStack ) ;
600633 self . clearBufferedCommand ( ) ;
601634 self . lines . level = [ ] ;
602635 self . displayPrompt ( ) ;
603636 }
604637 } ) ;
605638
606- self . resetContext ( ) ;
607- self . lines . level = [ ] ;
608-
609639 self . clearBufferedCommand ( ) ;
610640 ObjectDefineProperty ( this , 'bufferedCommand' , {
611641 get : deprecate ( ( ) => self [ kBufferedCommandSymbol ] ,
@@ -627,14 +657,16 @@ function REPLServer(prompt,
627657 }
628658
629659 Interface . call ( this , {
630- input : self . inputStream ,
631- output : self . outputStream ,
660+ input : options . input ,
661+ output : options . output ,
632662 completer : self . completer ,
633663 terminal : options . terminal ,
634664 historySize : options . historySize ,
635665 prompt
636666 } ) ;
637667
668+ self . resetContext ( ) ;
669+
638670 this . commands = ObjectCreate ( null ) ;
639671 defineDefaultCommands ( this ) ;
640672
@@ -752,7 +784,7 @@ function REPLServer(prompt,
752784 return ;
753785 }
754786 if ( ! self [ kBufferedCommandSymbol ] ) {
755- self . outputStream . write ( 'Invalid REPL keyword\n' ) ;
787+ self . output . write ( 'Invalid REPL keyword\n' ) ;
756788 finish ( null ) ;
757789 return ;
758790 }
@@ -769,7 +801,7 @@ function REPLServer(prompt,
769801 _memory . call ( self , cmd ) ;
770802
771803 if ( e && ! self [ kBufferedCommandSymbol ] && cmd . trim ( ) . startsWith ( 'npm ' ) ) {
772- self . outputStream . write ( 'npm should be run outside of the ' +
804+ self . output . write ( 'npm should be run outside of the ' +
773805 'node repl, in your normal shell.\n' +
774806 '(Press Control-D to exit.)\n' ) ;
775807 self . displayPrompt ( ) ;
@@ -804,7 +836,7 @@ function REPLServer(prompt,
804836 if ( ! self . underscoreAssigned ) {
805837 self . last = ret ;
806838 }
807- self . outputStream . write ( self . writer ( ret ) + '\n' ) ;
839+ self . output . write ( self . writer ( ret ) + '\n' ) ;
808840 }
809841
810842 // Display prompt again
@@ -814,10 +846,10 @@ function REPLServer(prompt,
814846
815847 self . on ( 'SIGCONT' , function onSigCont ( ) {
816848 if ( self . editorMode ) {
817- self . outputStream . write ( `${ self . _initialPrompt } .editor\n` ) ;
818- self . outputStream . write (
849+ self . output . write ( `${ self . _initialPrompt } .editor\n` ) ;
850+ self . output . write (
819851 '// Entering editor mode (^D to finish, ^C to cancel)\n' ) ;
820- self . outputStream . write ( `${ self [ kBufferedCommandSymbol ] } \n` ) ;
852+ self . output . write ( `${ self [ kBufferedCommandSymbol ] } \n` ) ;
821853 self . prompt ( true ) ;
822854 } else {
823855 self . displayPrompt ( true ) ;
@@ -957,7 +989,7 @@ REPLServer.prototype.createContext = function() {
957989 }
958990 }
959991 context . global = context ;
960- const _console = new Console ( this . outputStream ) ;
992+ const _console = new Console ( this . output ) ;
961993 ObjectDefineProperty ( context , 'console' , {
962994 configurable : true ,
963995 writable : true ,
@@ -998,7 +1030,7 @@ REPLServer.prototype.resetContext = function() {
9981030 this . last = value ;
9991031 if ( ! this . underscoreAssigned ) {
10001032 this . underscoreAssigned = true ;
1001- this . outputStream . write ( 'Expression assignment to _ now disabled.\n' ) ;
1033+ this . output . write ( 'Expression assignment to _ now disabled.\n' ) ;
10021034 }
10031035 }
10041036 } ) ;
@@ -1010,7 +1042,7 @@ REPLServer.prototype.resetContext = function() {
10101042 this . lastError = value ;
10111043 if ( ! this . underscoreErrAssigned ) {
10121044 this . underscoreErrAssigned = true ;
1013- this . outputStream . write (
1045+ this . output . write (
10141046 'Expression assignment to _error now disabled.\n' ) ;
10151047 }
10161048 }
@@ -1495,7 +1527,7 @@ function defineDefaultCommands(repl) {
14951527 action : function ( ) {
14961528 this . clearBufferedCommand ( ) ;
14971529 if ( ! this . useGlobal ) {
1498- this . outputStream . write ( 'Clearing context...\n' ) ;
1530+ this . output . write ( 'Clearing context...\n' ) ;
14991531 this . resetContext ( ) ;
15001532 }
15011533 this . displayPrompt ( ) ;
@@ -1522,9 +1554,9 @@ function defineDefaultCommands(repl) {
15221554 const cmd = this . commands [ name ] ;
15231555 const spaces = ' ' . repeat ( longestNameLength - name . length + 3 ) ;
15241556 const line = `.${ name } ${ cmd . help ? spaces + cmd . help : '' } \n` ;
1525- this . outputStream . write ( line ) ;
1557+ this . output . write ( line ) ;
15261558 }
1527- this . outputStream . write ( '\nPress ^C to abort current expression, ' +
1559+ this . output . write ( '\nPress ^C to abort current expression, ' +
15281560 '^D to exit the repl\n' ) ;
15291561 this . displayPrompt ( ) ;
15301562 }
@@ -1535,9 +1567,9 @@ function defineDefaultCommands(repl) {
15351567 action : function ( file ) {
15361568 try {
15371569 fs . writeFileSync ( file , this . lines . join ( '\n' ) ) ;
1538- this . outputStream . write ( `Session saved to: ${ file } \n` ) ;
1570+ this . output . write ( `Session saved to: ${ file } \n` ) ;
15391571 } catch {
1540- this . outputStream . write ( `Failed to save: ${ file } \n` ) ;
1572+ this . output . write ( `Failed to save: ${ file } \n` ) ;
15411573 }
15421574 this . displayPrompt ( ) ;
15431575 }
@@ -1555,12 +1587,12 @@ function defineDefaultCommands(repl) {
15551587 _turnOffEditorMode ( this ) ;
15561588 this . write ( '\n' ) ;
15571589 } else {
1558- this . outputStream . write (
1590+ this . output . write (
15591591 `Failed to load: ${ file } is not a valid file\n`
15601592 ) ;
15611593 }
15621594 } catch {
1563- this . outputStream . write ( `Failed to load: ${ file } \n` ) ;
1595+ this . output . write ( `Failed to load: ${ file } \n` ) ;
15641596 }
15651597 this . displayPrompt ( ) ;
15661598 }
@@ -1570,7 +1602,7 @@ function defineDefaultCommands(repl) {
15701602 help : 'Enter editor mode' ,
15711603 action ( ) {
15721604 _turnOnEditorMode ( this ) ;
1573- this . outputStream . write (
1605+ this . output . write (
15741606 '// Entering editor mode (^D to finish, ^C to cancel)\n' ) ;
15751607 }
15761608 } ) ;
0 commit comments