1
1
'use strict' ;
2
2
3
3
const {
4
+ ArrayPrototypeFilter,
5
+ ArrayPrototypeIncludes,
6
+ ArrayPrototypeMap,
7
+ Boolean,
8
+ FunctionPrototypeBind,
4
9
MathMin,
5
- Set,
10
+ RegExpPrototypeTest,
11
+ SafeSet,
12
+ StringPrototypeEndsWith,
13
+ StringPrototypeIndexOf,
14
+ StringPrototypeLastIndexOf,
15
+ StringPrototypeReplace,
16
+ StringPrototypeSlice,
17
+ StringPrototypeStartsWith,
18
+ StringPrototypeToLowerCase,
19
+ StringPrototypeTrim,
6
20
Symbol,
7
21
} = primordials ;
8
22
@@ -59,7 +73,9 @@ function isRecoverableError(e, code) {
59
73
// curly brace with parenthesis. Note: only the open parenthesis is added
60
74
// here as the point is to test for potentially valid but incomplete
61
75
// expressions.
62
- if ( / ^ \s * \{ / . test ( code ) && isRecoverableError ( e , `(${ code } ` ) ) return true ;
76
+ if ( RegExpPrototypeTest ( / ^ \s * \{ / , code ) &&
77
+ isRecoverableError ( e , `(${ code } ` ) )
78
+ return true ;
63
79
64
80
let recoverable = false ;
65
81
@@ -99,9 +115,11 @@ function isRecoverableError(e, code) {
99
115
break ;
100
116
101
117
case 'Unterminated string constant' :
102
- const token = this . input . slice ( this . lastTokStart , this . pos ) ;
118
+ const token = StringPrototypeSlice ( this . input ,
119
+ this . lastTokStart , this . pos ) ;
103
120
// See https://www.ecma-international.org/ecma-262/#sec-line-terminators
104
- if ( / \\ (?: \r \n ? | \n | \u2028 | \u2029 ) $ / . test ( token ) ) {
121
+ if ( RegExpPrototypeTest ( / \\ (?: \r \n ? | \n | \u2028 | \u2029 ) $ / ,
122
+ token ) ) {
105
123
recoverable = true ;
106
124
}
107
125
}
@@ -235,15 +253,15 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
235
253
hasCompletions = true ;
236
254
237
255
// If there is a common prefix to all matches, then apply that portion.
238
- const completions = rawCompletions . filter ( ( e ) => e ) ;
256
+ const completions = ArrayPrototypeFilter ( rawCompletions , Boolean ) ;
239
257
const prefix = commonPrefix ( completions ) ;
240
258
241
259
// No common prefix found.
242
260
if ( prefix . length <= completeOn . length ) {
243
261
return ;
244
262
}
245
263
246
- const suffix = prefix . slice ( completeOn . length ) ;
264
+ const suffix = StringPrototypeSlice ( prefix , completeOn . length ) ;
247
265
248
266
if ( insertPreview ) {
249
267
repl . _insertString ( suffix ) ;
@@ -271,16 +289,22 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
271
289
}
272
290
273
291
function isInStrictMode ( repl ) {
274
- return repl . replMode === REPL_MODE_STRICT || process . execArgv
275
- . map ( ( e ) => e . toLowerCase ( ) . replace ( / _ / g, '-' ) )
276
- . includes ( '--use-strict' ) ;
292
+ return repl . replMode === REPL_MODE_STRICT || ArrayPrototypeIncludes (
293
+ ArrayPrototypeMap ( process . execArgv ,
294
+ ( e ) => StringPrototypeReplace (
295
+ StringPrototypeToLowerCase ( e ) ,
296
+ / _ / g,
297
+ '-'
298
+ ) ) ,
299
+ '--use-strict' ) ;
277
300
}
278
301
279
302
// This returns a code preview for arbitrary input code.
280
303
function getInputPreview ( input , callback ) {
281
304
// For similar reasons as `defaultEval`, wrap expressions starting with a
282
305
// curly brace with parenthesis.
283
- if ( input . startsWith ( '{' ) && ! input . endsWith ( ';' ) && ! wrapped ) {
306
+ if ( StringPrototypeStartsWith ( input , '{' ) &&
307
+ ! StringPrototypeEndsWith ( input , ';' ) && ! wrapped ) {
284
308
input = `(${ input } )` ;
285
309
wrapped = true ;
286
310
}
@@ -346,7 +370,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
346
370
return ;
347
371
}
348
372
349
- const line = repl . line . trim ( ) ;
373
+ const line = StringPrototypeTrim ( repl . line ) ;
350
374
351
375
// Do not preview in case the line only contains whitespace.
352
376
if ( line === '' ) {
@@ -412,9 +436,9 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
412
436
413
437
// Line breaks are very rare and probably only occur in case of error
414
438
// messages with line breaks.
415
- const lineBreakPos = inspected . indexOf ( '\n' ) ;
439
+ const lineBreakPos = StringPrototypeIndexOf ( inspected , '\n' ) ;
416
440
if ( lineBreakPos !== - 1 ) {
417
- inspected = `${ inspected . slice ( 0 , lineBreakPos ) } ` ;
441
+ inspected = `${ StringPrototypeSlice ( inspected , 0 , lineBreakPos ) } ` ;
418
442
}
419
443
420
444
const result = repl . useColors ?
@@ -452,7 +476,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
452
476
// Refresh prints the whole screen again and the preview will be removed
453
477
// during that procedure. Print the preview again. This also makes sure
454
478
// the preview is always correct after resizing the terminal window.
455
- const originalRefresh = repl . _refreshLine . bind ( repl ) ;
479
+ const originalRefresh = FunctionPrototypeBind ( repl . _refreshLine , repl ) ;
456
480
repl . _refreshLine = ( ) => {
457
481
inputPreview = null ;
458
482
originalRefresh ( ) ;
@@ -462,7 +486,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
462
486
let insertCompletionPreview = true ;
463
487
// Insert the longest common suffix of the current input in case the user
464
488
// moves to the right while already being at the current input end.
465
- const originalMoveCursor = repl . _moveCursor . bind ( repl ) ;
489
+ const originalMoveCursor = FunctionPrototypeBind ( repl . _moveCursor , repl ) ;
466
490
repl . _moveCursor = ( dx ) => {
467
491
const currentCursor = repl . cursor ;
468
492
originalMoveCursor ( dx ) ;
@@ -476,7 +500,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
476
500
477
501
// This is the only function that interferes with the completion insertion.
478
502
// Monkey patch it to prevent inserting the completion when it shouldn't be.
479
- const originalClearLine = repl . clearLine . bind ( repl ) ;
503
+ const originalClearLine = FunctionPrototypeBind ( repl . clearLine , repl ) ;
480
504
repl . clearLine = ( ) => {
481
505
insertCompletionPreview = false ;
482
506
originalClearLine ( ) ;
@@ -492,7 +516,7 @@ function setupReverseSearch(repl) {
492
516
return { reverseSearch ( ) { return false ; } } ;
493
517
}
494
518
495
- const alreadyMatched = new Set ( ) ;
519
+ const alreadyMatched = new SafeSet ( ) ;
496
520
const labels = {
497
521
r : 'bck-i-search: ' ,
498
522
s : 'fwd-i-search: '
@@ -556,18 +580,18 @@ function setupReverseSearch(repl) {
556
580
if ( cursor === - 1 ) {
557
581
cursor = entry . length ;
558
582
}
559
- cursor = entry . lastIndexOf ( input , cursor - 1 ) ;
583
+ cursor = StringPrototypeLastIndexOf ( entry , input , cursor - 1 ) ;
560
584
} else {
561
- cursor = entry . indexOf ( input , cursor + 1 ) ;
585
+ cursor = StringPrototypeIndexOf ( entry , input , cursor + 1 ) ;
562
586
}
563
587
// Match not found.
564
588
if ( cursor === - 1 ) {
565
589
goToNextHistoryIndex ( ) ;
566
590
// Match found.
567
591
} else {
568
592
if ( repl . useColors ) {
569
- const start = entry . slice ( 0 , cursor ) ;
570
- const end = entry . slice ( cursor + input . length ) ;
593
+ const start = StringPrototypeSlice ( entry , 0 , cursor ) ;
594
+ const end = StringPrototypeSlice ( entry , cursor + input . length ) ;
571
595
entry = `${ start } \x1B[4m${ input } \x1B[24m${ end } ` ;
572
596
}
573
597
print ( entry , `${ labels [ dir ] } ${ input } _` , cursor ) ;
@@ -610,7 +634,7 @@ function setupReverseSearch(repl) {
610
634
// tick end instead of after each operation.
611
635
let rows = 0 ;
612
636
if ( lastMatch !== - 1 ) {
613
- const line = repl . history [ lastMatch ] . slice ( 0 , lastCursor ) ;
637
+ const line = StringPrototypeSlice ( repl . history [ lastMatch ] , 0 , lastCursor ) ;
614
638
rows = repl . _getDisplayPos ( `${ repl . getPrompt ( ) } ${ line } ` ) . rows ;
615
639
cursorTo ( repl . output , promptPos . cols ) ;
616
640
} else if ( isInReverseSearch && repl . line !== '' ) {
@@ -632,7 +656,7 @@ function setupReverseSearch(repl) {
632
656
// To know exactly how many rows we have to move the cursor back we need the
633
657
// cursor rows, the output rows and the input rows.
634
658
const prompt = repl . getPrompt ( ) ;
635
- const cursorLine = ` ${ prompt } ${ outputLine . slice ( 0 , cursor ) } ` ;
659
+ const cursorLine = prompt + StringPrototypeSlice ( outputLine , 0 , cursor ) ;
636
660
const cursorPos = repl . _getDisplayPos ( cursorLine ) ;
637
661
const outputPos = repl . _getDisplayPos ( `${ prompt } ${ outputLine } ` ) ;
638
662
const inputPos = repl . _getDisplayPos ( inputLine ) ;
@@ -690,7 +714,7 @@ function setupReverseSearch(repl) {
690
714
search ( ) ;
691
715
} else if ( key . name === 'backspace' ||
692
716
( key . ctrl && ( key . name === 'h' || key . name === 'w' ) ) ) {
693
- reset ( input . slice ( 0 , input . length - 1 ) ) ;
717
+ reset ( StringPrototypeSlice ( input , 0 , input . length - 1 ) ) ;
694
718
search ( ) ;
695
719
// Special handle <ctrl> + c and escape. Those should only cancel the
696
720
// reverse search. The original line is visible afterwards again.
0 commit comments