@@ -71,7 +71,6 @@ const {
71
71
deprecate
72
72
} = require ( 'internal/util' ) ;
73
73
const { inspect } = require ( 'internal/util/inspect' ) ;
74
- const Stream = require ( 'stream' ) ;
75
74
const vm = require ( 'vm' ) ;
76
75
const path = require ( 'path' ) ;
77
76
const fs = require ( 'fs' ) ;
@@ -115,7 +114,6 @@ const {
115
114
} = internalBinding ( 'contextify' ) ;
116
115
117
116
const history = require ( 'internal/repl/history' ) ;
118
- const { setImmediate } = require ( 'timers' ) ;
119
117
120
118
// Lazy-loaded.
121
119
let processTopLevelAwait ;
@@ -124,7 +122,6 @@ const globalBuiltins =
124
122
new Set ( vm . runInNewContext ( 'Object.getOwnPropertyNames(globalThis)' ) ) ;
125
123
126
124
const parentModule = module ;
127
- const replMap = new WeakMap ( ) ;
128
125
const domainSet = new WeakSet ( ) ;
129
126
130
127
const kBufferedCommandSymbol = Symbol ( 'bufferedCommand' ) ;
@@ -550,14 +547,13 @@ function REPLServer(prompt,
550
547
self . lastError = e ;
551
548
}
552
549
553
- const top = replMap . get ( self ) ;
554
550
if ( options [ kStandaloneREPL ] &&
555
551
process . listenerCount ( 'uncaughtException' ) !== 0 ) {
556
552
process . nextTick ( ( ) => {
557
553
process . emit ( 'uncaughtException' , e ) ;
558
- top . clearBufferedCommand ( ) ;
559
- top . lines . level = [ ] ;
560
- top . displayPrompt ( ) ;
554
+ self . clearBufferedCommand ( ) ;
555
+ self . lines . level = [ ] ;
556
+ self . displayPrompt ( ) ;
561
557
} ) ;
562
558
} else {
563
559
if ( errStack === '' ) {
@@ -583,10 +579,10 @@ function REPLServer(prompt,
583
579
}
584
580
// Normalize line endings.
585
581
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 ( ) ;
590
586
}
591
587
} ) ;
592
588
@@ -897,7 +893,6 @@ exports.start = function(prompt,
897
893
ignoreUndefined ,
898
894
replMode ) ;
899
895
if ( ! exports . repl ) exports . repl = repl ;
900
- replMap . set ( repl , repl ) ;
901
896
return repl ;
902
897
} ;
903
898
@@ -1034,23 +1029,6 @@ REPLServer.prototype.turnOffEditorMode = deprecate(
1034
1029
'REPLServer.turnOffEditorMode() is deprecated' ,
1035
1030
'DEP0078' ) ;
1036
1031
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
-
1054
1032
const requireRE = / \b r e q u i r e \s * \( [ ' " ] ( ( [ \w @ . / - ] + \/ ) ? (?: [ \w @ . / - ] * ) ) / ;
1055
1033
const fsAutoCompleteRE = / f s (?: \. p r o m i s e s ) ? \. \s * [ a - z ] [ a - z A - Z ] + \( \s * [ " ' ] ( .* ) / ;
1056
1034
const simpleExpressionRE =
@@ -1110,38 +1088,13 @@ REPLServer.prototype.complete = function() {
1110
1088
// Warning: This eval's code like "foo.bar.baz", so it will run property
1111
1089
// getter code.
1112
1090
function 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
-
1141
1091
// List of completion lists, one for each inheritance "level"
1142
1092
let completionGroups = [ ] ;
1143
1093
let completeOn , group ;
1144
1094
1095
+ // Ignore right whitespace. It could change the outcome.
1096
+ line = line . trimLeft ( ) ;
1097
+
1145
1098
// REPL commands (e.g. ".break").
1146
1099
let filter ;
1147
1100
let match = line . match ( / ^ \s * \. ( \w * ) $ / ) ;
@@ -1465,8 +1418,7 @@ function _memory(cmd) {
1465
1418
// scope will not work for this function.
1466
1419
self . lines . level . push ( {
1467
1420
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
1470
1422
} ) ;
1471
1423
} else if ( depth < 0 ) {
1472
1424
// Going... up.
0 commit comments