@@ -71,7 +71,6 @@ const {
7171 deprecate
7272} = require ( 'internal/util' ) ;
7373const { inspect } = require ( 'internal/util/inspect' ) ;
74- const Stream = require ( 'stream' ) ;
7574const vm = require ( 'vm' ) ;
7675const path = require ( 'path' ) ;
7776const fs = require ( 'fs' ) ;
@@ -115,7 +114,6 @@ const {
115114} = internalBinding ( 'contextify' ) ;
116115
117116const history = require ( 'internal/repl/history' ) ;
118- const { setImmediate } = require ( 'timers' ) ;
119117
120118// Lazy-loaded.
121119let processTopLevelAwait ;
@@ -124,7 +122,6 @@ const globalBuiltins =
124122 new Set ( vm . runInNewContext ( 'Object.getOwnPropertyNames(globalThis)' ) ) ;
125123
126124const parentModule = module ;
127- const replMap = new WeakMap ( ) ;
128125const domainSet = new WeakSet ( ) ;
129126
130127const kBufferedCommandSymbol = Symbol ( 'bufferedCommand' ) ;
@@ -550,14 +547,13 @@ function REPLServer(prompt,
550547 self . lastError = e ;
551548 }
552549
553- const top = replMap . get ( self ) ;
554550 if ( options [ kStandaloneREPL ] &&
555551 process . listenerCount ( 'uncaughtException' ) !== 0 ) {
556552 process . nextTick ( ( ) => {
557553 process . emit ( 'uncaughtException' , e ) ;
558- top . clearBufferedCommand ( ) ;
559- top . lines . level = [ ] ;
560- top . displayPrompt ( ) ;
554+ self . clearBufferedCommand ( ) ;
555+ self . lines . level = [ ] ;
556+ self . displayPrompt ( ) ;
561557 } ) ;
562558 } else {
563559 if ( errStack === '' ) {
@@ -583,10 +579,10 @@ function REPLServer(prompt,
583579 }
584580 // Normalize line endings.
585581 errStack += errStack . endsWith ( '\n' ) ? '' : '\n' ;
586- top . outputStream . write ( errStack ) ;
587- top . clearBufferedCommand ( ) ;
588- top . lines . level = [ ] ;
589- top . displayPrompt ( ) ;
582+ self . outputStream . write ( errStack ) ;
583+ self . clearBufferedCommand ( ) ;
584+ self . lines . level = [ ] ;
585+ self . displayPrompt ( ) ;
590586 }
591587 } ) ;
592588
@@ -897,7 +893,6 @@ exports.start = function(prompt,
897893 ignoreUndefined ,
898894 replMode ) ;
899895 if ( ! exports . repl ) exports . repl = repl ;
900- replMap . set ( repl , repl ) ;
901896 return repl ;
902897} ;
903898
@@ -1034,23 +1029,6 @@ REPLServer.prototype.turnOffEditorMode = deprecate(
10341029 'REPLServer.turnOffEditorMode() is deprecated' ,
10351030 'DEP0078' ) ;
10361031
1037- // A stream to push an array into a REPL
1038- // used in REPLServer.complete
1039- function ArrayStream ( ) {
1040- Stream . call ( this ) ;
1041-
1042- this . run = function ( data ) {
1043- for ( let n = 0 ; n < data . length ; n ++ )
1044- this . emit ( 'data' , `${ data [ n ] } \n` ) ;
1045- } ;
1046- }
1047- ObjectSetPrototypeOf ( ArrayStream . prototype , Stream . prototype ) ;
1048- ObjectSetPrototypeOf ( ArrayStream , Stream ) ;
1049- ArrayStream . prototype . readable = true ;
1050- ArrayStream . prototype . writable = true ;
1051- ArrayStream . prototype . resume = function ( ) { } ;
1052- ArrayStream . prototype . write = function ( ) { } ;
1053-
10541032const requireRE = / \b r e q u i r e \s * \( [ ' " ] ( ( [ \w @ . / - ] + \/ ) ? (?: [ \w @ . / - ] * ) ) / ;
10551033const fsAutoCompleteRE = / f s (?: \. p r o m i s e s ) ? \. \s * [ a - z ] [ a - z A - Z ] + \( \s * [ " ' ] ( .* ) / ;
10561034const simpleExpressionRE =
@@ -1110,38 +1088,13 @@ REPLServer.prototype.complete = function() {
11101088// Warning: This eval's code like "foo.bar.baz", so it will run property
11111089// getter code.
11121090function complete ( line , callback ) {
1113- // There may be local variables to evaluate, try a nested REPL
1114- if ( this [ kBufferedCommandSymbol ] !== undefined &&
1115- this [ kBufferedCommandSymbol ] . length ) {
1116- // Get a new array of inputted lines
1117- const tmp = this . lines . slice ( ) ;
1118- // Kill off all function declarations to push all local variables into
1119- // global scope
1120- for ( let n = 0 ; n < this . lines . level . length ; n ++ ) {
1121- const kill = this . lines . level [ n ] ;
1122- if ( kill . isFunction )
1123- tmp [ kill . line ] = '' ;
1124- }
1125- const flat = new ArrayStream ( ) ; // Make a new "input" stream.
1126- const magic = new REPLServer ( '' , flat ) ; // Make a nested REPL.
1127- replMap . set ( magic , replMap . get ( this ) ) ;
1128- flat . run ( tmp ) ; // `eval` the flattened code.
1129- // All this is only profitable if the nested REPL does not have a
1130- // bufferedCommand.
1131- if ( ! magic [ kBufferedCommandSymbol ] ) {
1132- magic . _domain . on ( 'error' , ( err ) => {
1133- setImmediate ( ( ) => {
1134- throw err ;
1135- } ) ;
1136- } ) ;
1137- return magic . complete ( line , callback ) ;
1138- }
1139- }
1140-
11411091 // List of completion lists, one for each inheritance "level"
11421092 let completionGroups = [ ] ;
11431093 let completeOn , group ;
11441094
1095+ // Ignore right whitespace. It could change the outcome.
1096+ line = line . trimLeft ( ) ;
1097+
11451098 // REPL commands (e.g. ".break").
11461099 let filter ;
11471100 let match = line . match ( / ^ \s * \. ( \w * ) $ / ) ;
@@ -1465,8 +1418,7 @@ function _memory(cmd) {
14651418 // scope will not work for this function.
14661419 self . lines . level . push ( {
14671420 line : self . lines . length - 1 ,
1468- depth : depth ,
1469- isFunction : / \b f u n c t i o n \b / . test ( cmd )
1421+ depth : depth
14701422 } ) ;
14711423 } else if ( depth < 0 ) {
14721424 // Going... up.
0 commit comments