@@ -59,7 +59,6 @@ const {
5959 RegExp,
6060 Set,
6161 Symbol,
62- WeakMap,
6362 WeakSet,
6463} = primordials ;
6564
@@ -78,7 +77,6 @@ const {
7877 deprecate
7978} = require ( 'internal/util' ) ;
8079const { inspect } = require ( 'internal/util/inspect' ) ;
81- const Stream = require ( 'stream' ) ;
8280const vm = require ( 'vm' ) ;
8381const path = require ( 'path' ) ;
8482const fs = require ( 'fs' ) ;
@@ -123,7 +121,6 @@ const {
123121} = internalBinding ( 'contextify' ) ;
124122
125123const history = require ( 'internal/repl/history' ) ;
126- const { setImmediate } = require ( 'timers' ) ;
127124
128125// Lazy-loaded.
129126let processTopLevelAwait ;
@@ -132,7 +129,6 @@ const globalBuiltins =
132129 new Set ( vm . runInNewContext ( 'Object.getOwnPropertyNames(globalThis)' ) ) ;
133130
134131const parentModule = module ;
135- const replMap = new WeakMap ( ) ;
136132const domainSet = new WeakSet ( ) ;
137133
138134const kBufferedCommandSymbol = Symbol ( 'bufferedCommand' ) ;
@@ -558,14 +554,13 @@ function REPLServer(prompt,
558554 self . lastError = e ;
559555 }
560556
561- const top = replMap . get ( self ) ;
562557 if ( options [ kStandaloneREPL ] &&
563558 process . listenerCount ( 'uncaughtException' ) !== 0 ) {
564559 process . nextTick ( ( ) => {
565560 process . emit ( 'uncaughtException' , e ) ;
566- top . clearBufferedCommand ( ) ;
567- top . lines . level = [ ] ;
568- top . displayPrompt ( ) ;
561+ self . clearBufferedCommand ( ) ;
562+ self . lines . level = [ ] ;
563+ self . displayPrompt ( ) ;
569564 } ) ;
570565 } else {
571566 if ( errStack === '' ) {
@@ -591,10 +586,10 @@ function REPLServer(prompt,
591586 }
592587 // Normalize line endings.
593588 errStack += errStack . endsWith ( '\n' ) ? '' : '\n' ;
594- top . outputStream . write ( errStack ) ;
595- top . clearBufferedCommand ( ) ;
596- top . lines . level = [ ] ;
597- top . displayPrompt ( ) ;
589+ self . outputStream . write ( errStack ) ;
590+ self . clearBufferedCommand ( ) ;
591+ self . lines . level = [ ] ;
592+ self . displayPrompt ( ) ;
598593 }
599594 } ) ;
600595
@@ -905,7 +900,6 @@ exports.start = function(prompt,
905900 ignoreUndefined ,
906901 replMode ) ;
907902 if ( ! exports . repl ) exports . repl = repl ;
908- replMap . set ( repl , repl ) ;
909903 return repl ;
910904} ;
911905
@@ -1042,23 +1036,6 @@ REPLServer.prototype.turnOffEditorMode = deprecate(
10421036 'REPLServer.turnOffEditorMode() is deprecated' ,
10431037 'DEP0078' ) ;
10441038
1045- // A stream to push an array into a REPL
1046- // used in REPLServer.complete
1047- function ArrayStream ( ) {
1048- Stream . call ( this ) ;
1049-
1050- this . run = function ( data ) {
1051- for ( let n = 0 ; n < data . length ; n ++ )
1052- this . emit ( 'data' , `${ data [ n ] } \n` ) ;
1053- } ;
1054- }
1055- ObjectSetPrototypeOf ( ArrayStream . prototype , Stream . prototype ) ;
1056- ObjectSetPrototypeOf ( ArrayStream , Stream ) ;
1057- ArrayStream . prototype . readable = true ;
1058- ArrayStream . prototype . writable = true ;
1059- ArrayStream . prototype . resume = function ( ) { } ;
1060- ArrayStream . prototype . write = function ( ) { } ;
1061-
10621039const requireRE = / \b r e q u i r e \s * \( [ ' " ] ( ( [ \w @ . / - ] + \/ ) ? (?: [ \w @ . / - ] * ) ) / ;
10631040const fsAutoCompleteRE = / f s (?: \. p r o m i s e s ) ? \. \s * [ a - z ] [ a - z A - Z ] + \( \s * [ " ' ] ( .* ) / ;
10641041const simpleExpressionRE =
@@ -1118,40 +1095,13 @@ REPLServer.prototype.complete = function() {
11181095// Warning: This eval's code like "foo.bar.baz", so it will run property
11191096// getter code.
11201097function complete ( line , callback ) {
1121- // There may be local variables to evaluate, try a nested REPL
1122- if ( this [ kBufferedCommandSymbol ] !== undefined &&
1123- this [ kBufferedCommandSymbol ] . length ) {
1124- // Get a new array of inputted lines
1125- const tmp = this . lines . slice ( ) ;
1126- // Kill off all function declarations to push all local variables into
1127- // global scope
1128- for ( let n = 0 ; n < this . lines . level . length ; n ++ ) {
1129- const kill = this . lines . level [ n ] ;
1130- if ( kill . isFunction )
1131- tmp [ kill . line ] = '' ;
1132- }
1133- const flat = new ArrayStream ( ) ; // Make a new "input" stream.
1134- const magic = new REPLServer ( '' , flat ) ; // Make a nested REPL.
1135- replMap . set ( magic , replMap . get ( this ) ) ;
1136- flat . run ( tmp ) ; // `eval` the flattened code.
1137- // All this is only profitable if the nested REPL does not have a
1138- // bufferedCommand.
1139- if ( ! magic [ kBufferedCommandSymbol ] ) {
1140- magic . _domain . on ( 'error' , ( err ) => {
1141- if ( ! cjsLoader . asyncRunMain )
1142- throw err ;
1143- setImmediate ( ( ) => {
1144- throw err ;
1145- } ) ;
1146- } ) ;
1147- return magic . complete ( line , callback ) ;
1148- }
1149- }
1150-
11511098 // List of completion lists, one for each inheritance "level"
11521099 let completionGroups = [ ] ;
11531100 let completeOn , group ;
11541101
1102+ // Ignore right whitespace. It could change the outcome.
1103+ line = line . trimLeft ( ) ;
1104+
11551105 // REPL commands (e.g. ".break").
11561106 let filter ;
11571107 let match = line . match ( / ^ \s * \. ( \w * ) $ / ) ;
@@ -1475,8 +1425,7 @@ function _memory(cmd) {
14751425 // scope will not work for this function.
14761426 self . lines . level . push ( {
14771427 line : self . lines . length - 1 ,
1478- depth : depth ,
1479- isFunction : / \b f u n c t i o n \b / . test ( cmd )
1428+ depth : depth
14801429 } ) ;
14811430 } else if ( depth < 0 ) {
14821431 // Going... up.
0 commit comments