@@ -73,6 +73,7 @@ for (var n = 0; n < GLOBAL_OBJECT_PROPERTIES.length; n++) {
73
73
GLOBAL_OBJECT_PROPERTY_MAP [ GLOBAL_OBJECT_PROPERTIES [ n ] ] =
74
74
GLOBAL_OBJECT_PROPERTIES [ n ] ;
75
75
}
76
+ const kBufferedCommandSymbol = Symbol ( 'bufferedCommand' ) ;
76
77
77
78
try {
78
79
// hack for require.resolve("./relative") to work properly.
@@ -300,7 +301,7 @@ function REPLServer(prompt,
300
301
} else {
301
302
top . outputStream . write ( `Thrown: ${ String ( e ) } \n` ) ;
302
303
}
303
- top . bufferedCommand = '' ;
304
+ top . clearBufferedCommand ( ) ;
304
305
top . lines . level = [ ] ;
305
306
top . displayPrompt ( ) ;
306
307
} ) ;
@@ -326,9 +327,17 @@ function REPLServer(prompt,
326
327
self . outputStream = output ;
327
328
328
329
self . resetContext ( ) ;
329
- self . bufferedCommand = '' ;
330
330
self . lines . level = [ ] ;
331
331
332
+ self . clearBufferedCommand ( ) ;
333
+ Object . defineProperty ( this , 'bufferedCommand' , {
334
+ get : util . deprecate ( ( ) => self [ kBufferedCommandSymbol ] ,
335
+ 'REPLServer.bufferedCommand is deprecated' , 'DEP0074' ) ,
336
+ set : util . deprecate ( ( val ) => self [ kBufferedCommandSymbol ] = val ,
337
+ 'REPLServer.bufferedCommand is deprecated' , 'DEP0074' ) ,
338
+ enumerable : true
339
+ } ) ;
340
+
332
341
// Figure out which "complete" function to use.
333
342
self . completer = ( typeof options . completer === 'function' ) ?
334
343
options . completer : completer ;
@@ -376,7 +385,8 @@ function REPLServer(prompt,
376
385
self . clearLine ( ) ;
377
386
self . turnOffEditorMode ( ) ;
378
387
379
- if ( ! ( self . bufferedCommand && self . bufferedCommand . length > 0 ) && empty ) {
388
+ const cmd = self [ kBufferedCommandSymbol ] ;
389
+ if ( ! ( cmd && cmd . length > 0 ) && empty ) {
380
390
if ( sawSIGINT ) {
381
391
self . close ( ) ;
382
392
sawSIGINT = false ;
@@ -388,7 +398,7 @@ function REPLServer(prompt,
388
398
sawSIGINT = false ;
389
399
}
390
400
391
- self . bufferedCommand = '' ;
401
+ self . clearBufferedCommand ( ) ;
392
402
self . lines . level = [ ] ;
393
403
self . displayPrompt ( ) ;
394
404
} ) ;
@@ -399,7 +409,7 @@ function REPLServer(prompt,
399
409
sawSIGINT = false ;
400
410
401
411
if ( self . editorMode ) {
402
- self . bufferedCommand += cmd + '\n' ;
412
+ self [ kBufferedCommandSymbol ] += cmd + '\n' ;
403
413
404
414
// code alignment
405
415
const matches = self . _sawKeyPress ? cmd . match ( / ^ \s + / ) : null ;
@@ -427,15 +437,15 @@ function REPLServer(prompt,
427
437
if ( self . parseREPLKeyword ( keyword , rest ) === true ) {
428
438
return ;
429
439
}
430
- if ( ! self . bufferedCommand ) {
440
+ if ( ! self [ kBufferedCommandSymbol ] ) {
431
441
self . outputStream . write ( 'Invalid REPL keyword\n' ) ;
432
442
finish ( null ) ;
433
443
return ;
434
444
}
435
445
}
436
446
}
437
447
438
- const evalCmd = self . bufferedCommand + cmd + '\n' ;
448
+ const evalCmd = self [ kBufferedCommandSymbol ] + cmd + '\n' ;
439
449
440
450
debug ( 'eval %j' , evalCmd ) ;
441
451
self . eval ( evalCmd , self . context , 'repl' , finish ) ;
@@ -444,11 +454,11 @@ function REPLServer(prompt,
444
454
debug ( 'finish' , e , ret ) ;
445
455
self . memory ( cmd ) ;
446
456
447
- if ( e && ! self . bufferedCommand && cmd . trim ( ) . startsWith ( 'npm ' ) ) {
457
+ if ( e && ! self [ kBufferedCommandSymbol ] && cmd . trim ( ) . startsWith ( 'npm ' ) ) {
448
458
self . outputStream . write ( 'npm should be run outside of the ' +
449
459
'node repl, in your normal shell.\n' +
450
460
'(Press Control-D to exit.)\n' ) ;
451
- self . bufferedCommand = '' ;
461
+ self . clearBufferedCommand ( ) ;
452
462
self . displayPrompt ( ) ;
453
463
return ;
454
464
}
@@ -460,7 +470,7 @@ function REPLServer(prompt,
460
470
// {
461
471
// ... x: 1
462
472
// ... }
463
- self . bufferedCommand += cmd + '\n' ;
473
+ self [ kBufferedCommandSymbol ] += cmd + '\n' ;
464
474
self . displayPrompt ( ) ;
465
475
return ;
466
476
} else {
@@ -469,7 +479,7 @@ function REPLServer(prompt,
469
479
}
470
480
471
481
// Clear buffer if no SyntaxErrors
472
- self . bufferedCommand = '' ;
482
+ self . clearBufferedCommand ( ) ;
473
483
sawCtrlD = false ;
474
484
475
485
// If we got any output - print it (if no error)
@@ -495,7 +505,7 @@ function REPLServer(prompt,
495
505
self . outputStream . write ( `${ self . _initialPrompt } .editor\n` ) ;
496
506
self . outputStream . write (
497
507
'// Entering editor mode (^D to finish, ^C to cancel)\n' ) ;
498
- self . outputStream . write ( `${ self . bufferedCommand } \n` ) ;
508
+ self . outputStream . write ( `${ self [ kBufferedCommandSymbol ] } \n` ) ;
499
509
self . prompt ( true ) ;
500
510
} else {
501
511
self . displayPrompt ( true ) ;
@@ -569,6 +579,10 @@ exports.start = function(prompt,
569
579
return repl ;
570
580
} ;
571
581
582
+ REPLServer . prototype . clearBufferedCommand = function clearBufferedCommand ( ) {
583
+ this [ kBufferedCommandSymbol ] = '' ;
584
+ } ;
585
+
572
586
REPLServer . prototype . close = function close ( ) {
573
587
if ( this . terminal && this . _flushing && ! this . _closingOnFlush ) {
574
588
this . _closingOnFlush = true ;
@@ -647,7 +661,7 @@ REPLServer.prototype.resetContext = function() {
647
661
648
662
REPLServer . prototype . displayPrompt = function ( preserveCursor ) {
649
663
var prompt = this . _initialPrompt ;
650
- if ( this . bufferedCommand . length ) {
664
+ if ( this [ kBufferedCommandSymbol ] . length ) {
651
665
prompt = '...' ;
652
666
const len = this . lines . level . length ? this . lines . level . length - 1 : 0 ;
653
667
const levelInd = '..' . repeat ( len ) ;
@@ -742,7 +756,8 @@ REPLServer.prototype.complete = function() {
742
756
// getter code.
743
757
function complete ( line , callback ) {
744
758
// There may be local variables to evaluate, try a nested REPL
745
- if ( this . bufferedCommand !== undefined && this . bufferedCommand . length ) {
759
+ if ( this [ kBufferedCommandSymbol ] !== undefined &&
760
+ this [ kBufferedCommandSymbol ] . length ) {
746
761
// Get a new array of inputted lines
747
762
var tmp = this . lines . slice ( ) ;
748
763
// Kill off all function declarations to push all local variables into
@@ -759,7 +774,7 @@ function complete(line, callback) {
759
774
flat . run ( tmp ) ; // eval the flattened code
760
775
// all this is only profitable if the nested REPL
761
776
// does not have a bufferedCommand
762
- if ( ! magic . bufferedCommand ) {
777
+ if ( ! magic [ kBufferedCommandSymbol ] ) {
763
778
return magic . complete ( line , callback ) ;
764
779
}
765
780
}
@@ -1172,7 +1187,7 @@ function defineDefaultCommands(repl) {
1172
1187
repl . defineCommand ( 'break' , {
1173
1188
help : 'Sometimes you get stuck, this gets you out' ,
1174
1189
action : function ( ) {
1175
- this . bufferedCommand = '' ;
1190
+ this . clearBufferedCommand ( ) ;
1176
1191
this . displayPrompt ( ) ;
1177
1192
}
1178
1193
} ) ;
@@ -1186,7 +1201,7 @@ function defineDefaultCommands(repl) {
1186
1201
repl . defineCommand ( 'clear' , {
1187
1202
help : clearMessage ,
1188
1203
action : function ( ) {
1189
- this . bufferedCommand = '' ;
1204
+ this . clearBufferedCommand ( ) ;
1190
1205
if ( ! this . useGlobal ) {
1191
1206
this . outputStream . write ( 'Clearing context...\n' ) ;
1192
1207
this . resetContext ( ) ;
0 commit comments