2222/* A repl library that you can include in your own code to get a runtime
2323 * interface to your program.
2424 *
25- * var repl = require("repl");
25+ * const repl = require("repl");
2626 * // start repl on stdin
2727 * repl.start("prompt> ");
2828 *
@@ -372,7 +372,7 @@ function REPLServer(prompt,
372372
373373 // After executing the current expression, store the values of RegExp
374374 // predefined properties back in `savedRegExMatches`
375- for ( var idx = 1 ; idx < savedRegExMatches . length ; idx += 1 ) {
375+ for ( let idx = 1 ; idx < savedRegExMatches . length ; idx += 1 ) {
376376 savedRegExMatches [ idx ] = RegExp [ `$${ idx } ` ] ;
377377 }
378378
@@ -636,8 +636,8 @@ function REPLServer(prompt,
636636 self . emit ( 'exit' ) ;
637637 } ) ;
638638
639- var sawSIGINT = false ;
640- var sawCtrlD = false ;
639+ let sawSIGINT = false ;
640+ let sawCtrlD = false ;
641641 const prioritizedSigintQueue = new Set ( ) ;
642642 self . on ( 'SIGINT' , function onSigInt ( ) {
643643 if ( prioritizedSigintQueue . size > 0 ) {
@@ -877,7 +877,7 @@ REPLServer.prototype.close = function close() {
877877} ;
878878
879879REPLServer . prototype . createContext = function ( ) {
880- var context ;
880+ let context ;
881881 if ( this . useGlobal ) {
882882 context = global ;
883883 } else {
@@ -963,7 +963,7 @@ REPLServer.prototype.resetContext = function() {
963963} ;
964964
965965REPLServer . prototype . displayPrompt = function ( preserveCursor ) {
966- var prompt = this . _initialPrompt ;
966+ let prompt = this . _initialPrompt ;
967967 if ( this [ kBufferedCommandSymbol ] . length ) {
968968 prompt = '...' ;
969969 const len = this . lines . level . length ? this . lines . level . length - 1 : 0 ;
@@ -993,7 +993,7 @@ function ArrayStream() {
993993 Stream . call ( this ) ;
994994
995995 this . run = function ( data ) {
996- for ( var n = 0 ; n < data . length ; n ++ )
996+ for ( let n = 0 ; n < data . length ; n ++ )
997997 this . emit ( 'data' , `${ data [ n ] } \n` ) ;
998998 } ;
999999}
@@ -1018,7 +1018,7 @@ function isIdentifier(str) {
10181018 return false ;
10191019 }
10201020 const firstLen = first > 0xffff ? 2 : 1 ;
1021- for ( var i = firstLen ; i < str . length ; i += 1 ) {
1021+ for ( let i = firstLen ; i < str . length ; i += 1 ) {
10221022 const cp = str . codePointAt ( i ) ;
10231023 if ( ! isIdentifierChar ( cp ) ) {
10241024 return false ;
@@ -1056,7 +1056,7 @@ REPLServer.prototype.complete = function() {
10561056// given to the readline interface for handling tab completion.
10571057//
10581058// Example:
1059- // complete('var foo = util.')
1059+ // complete('let foo = util.')
10601060// -> [['util.print', 'util.debug', 'util.log', 'util.inspect'],
10611061// 'util.' ]
10621062//
@@ -1067,16 +1067,16 @@ function complete(line, callback) {
10671067 if ( this [ kBufferedCommandSymbol ] !== undefined &&
10681068 this [ kBufferedCommandSymbol ] . length ) {
10691069 // Get a new array of inputted lines
1070- var tmp = this . lines . slice ( ) ;
1070+ const tmp = this . lines . slice ( ) ;
10711071 // Kill off all function declarations to push all local variables into
10721072 // global scope
1073- for ( var n = 0 ; n < this . lines . level . length ; n ++ ) {
1074- var kill = this . lines . level [ n ] ;
1073+ for ( let n = 0 ; n < this . lines . level . length ; n ++ ) {
1074+ const kill = this . lines . level [ n ] ;
10751075 if ( kill . isFunction )
10761076 tmp [ kill . line ] = '' ;
10771077 }
1078- var flat = new ArrayStream ( ) ; // Make a new "input" stream.
1079- var magic = new REPLServer ( '' , flat ) ; // Make a nested REPL.
1078+ const flat = new ArrayStream ( ) ; // Make a new "input" stream.
1079+ const magic = new REPLServer ( '' , flat ) ; // Make a nested REPL.
10801080 replMap . set ( magic , replMap . get ( this ) ) ;
10811081 flat . run ( tmp ) ; // `eval` the flattened code.
10821082 // All this is only profitable if the nested REPL does not have a
@@ -1087,13 +1087,12 @@ function complete(line, callback) {
10871087 }
10881088 }
10891089
1090- var completions ;
10911090 // List of completion lists, one for each inheritance "level"
1092- var completionGroups = [ ] ;
1093- var completeOn , group , c ;
1091+ let completionGroups = [ ] ;
1092+ let completeOn , group ;
10941093
10951094 // REPL commands (e.g. ".break").
1096- var filter ;
1095+ let filter ;
10971096 let match = line . match ( / ^ \s * \. ( \w * ) $ / ) ;
10981097 if ( match ) {
10991098 completionGroups . push ( Object . keys ( this . commands ) ) ;
@@ -1106,14 +1105,14 @@ function complete(line, callback) {
11061105 } else if ( match = line . match ( requireRE ) ) {
11071106 // require('...<Tab>')
11081107 const exts = Object . keys ( this . context . require . extensions ) ;
1109- var indexRe = new RegExp ( '^index(?:' + exts . map ( regexpEscape ) . join ( '|' ) +
1108+ const indexRe = new RegExp ( '^index(?:' + exts . map ( regexpEscape ) . join ( '|' ) +
11101109 ')$' ) ;
1111- var versionedFileNamesRe = / - \d + \. \d + / ;
1110+ const versionedFileNamesRe = / - \d + \. \d + / ;
11121111
11131112 completeOn = match [ 1 ] ;
1114- var subdir = match [ 2 ] || '' ;
1113+ const subdir = match [ 2 ] || '' ;
11151114 filter = match [ 1 ] ;
1116- var dir , files , name , base , ext , abs , subfiles , isDirectory ;
1115+ let dir , files , name , base , ext , abs , subfiles , isDirectory ;
11171116 group = [ ] ;
11181117 let paths = [ ] ;
11191118
@@ -1211,7 +1210,7 @@ function complete(line, callback) {
12111210 } else if ( line . length === 0 || / \w | \. | \$ / . test ( line [ line . length - 1 ] ) ) {
12121211 match = simpleExpressionRE . exec ( line ) ;
12131212 if ( line . length === 0 || match ) {
1214- var expr ;
1213+ let expr ;
12151214 completeOn = ( match ? match [ 0 ] : '' ) ;
12161215 if ( line . length === 0 ) {
12171216 filter = '' ;
@@ -1220,19 +1219,19 @@ function complete(line, callback) {
12201219 filter = '' ;
12211220 expr = match [ 0 ] . slice ( 0 , match [ 0 ] . length - 1 ) ;
12221221 } else {
1223- var bits = match [ 0 ] . split ( '.' ) ;
1222+ const bits = match [ 0 ] . split ( '.' ) ;
12241223 filter = bits . pop ( ) ;
12251224 expr = bits . join ( '.' ) ;
12261225 }
12271226
12281227 // Resolve expr and get its completions.
1229- var memberGroups = [ ] ;
1228+ const memberGroups = [ ] ;
12301229 if ( ! expr ) {
12311230 // If context is instance of vm.ScriptContext
12321231 // Get global vars synchronously
12331232 if ( this . useGlobal || vm . isContext ( this . context ) ) {
12341233 completionGroups . push ( getGlobalLexicalScopeNames ( this [ kContextId ] ) ) ;
1235- var contextProto = this . context ;
1234+ let contextProto = this . context ;
12361235 while ( contextProto = Object . getPrototypeOf ( contextProto ) ) {
12371236 completionGroups . push (
12381237 filteredOwnPropertyNames . call ( this , contextProto ) ) ;
@@ -1247,7 +1246,7 @@ function complete(line, callback) {
12471246 if ( filter !== '' ) addCommonWords ( completionGroups ) ;
12481247 } else if ( Array . isArray ( globals [ 0 ] ) ) {
12491248 // Add grouped globals
1250- for ( var n = 0 ; n < globals . length ; n ++ )
1249+ for ( let n = 0 ; n < globals . length ; n ++ )
12511250 completionGroups . push ( globals [ n ] ) ;
12521251 } else {
12531252 completionGroups . push ( globals ) ;
@@ -1272,8 +1271,8 @@ function complete(line, callback) {
12721271 }
12731272 // Works for non-objects
12741273 try {
1275- var sentinel = 5 ;
1276- var p ;
1274+ let sentinel = 5 ;
1275+ let p ;
12771276 if ( typeof obj === 'object' || typeof obj === 'function' ) {
12781277 p = Object . getPrototypeOf ( obj ) ;
12791278 } else {
@@ -1316,7 +1315,7 @@ function complete(line, callback) {
13161315 function completionGroupsLoaded ( ) {
13171316 // Filter, sort (within each group), uniq and merge the completion groups.
13181317 if ( completionGroups . length && filter ) {
1319- var newCompletionGroups = [ ] ;
1318+ const newCompletionGroups = [ ] ;
13201319 for ( let i = 0 ; i < completionGroups . length ; i ++ ) {
13211320 group = completionGroups [ i ]
13221321 . filter ( ( elem ) => elem . indexOf ( filter ) === 0 ) ;
@@ -1327,17 +1326,19 @@ function complete(line, callback) {
13271326 completionGroups = newCompletionGroups ;
13281327 }
13291328
1329+ let completions ;
1330+
13301331 if ( completionGroups . length ) {
1331- var uniq = { } ; // Unique completions across all groups
1332+ const uniq = { } ; // Unique completions across all groups
13321333 completions = [ ] ;
13331334 // Completion group 0 is the "closest"
13341335 // (least far up the inheritance chain)
13351336 // so we put its completions last: to be closest in the REPL.
13361337 for ( let i = 0 ; i < completionGroups . length ; i ++ ) {
13371338 group = completionGroups [ i ] ;
13381339 group . sort ( ) ;
1339- for ( var j = group . length - 1 ; j >= 0 ; j -- ) {
1340- c = group [ j ] ;
1340+ for ( let j = group . length - 1 ; j >= 0 ; j -- ) {
1341+ const c = group [ j ] ;
13411342 if ( ! ObjectPrototype . hasOwnProperty ( uniq , c ) ) {
13421343 completions . unshift ( c ) ;
13431344 uniq [ c ] = true ;
@@ -1361,9 +1362,9 @@ function longestCommonPrefix(arr = []) {
13611362
13621363 const first = arr [ 0 ] ;
13631364 // complexity: O(m * n)
1364- for ( var m = 0 ; m < first . length ; m ++ ) {
1365+ for ( let m = 0 ; m < first . length ; m ++ ) {
13651366 const c = first [ m ] ;
1366- for ( var n = 1 ; n < cnt ; n ++ ) {
1367+ for ( let n = 1 ; n < cnt ; n ++ ) {
13671368 const entry = arr [ n ] ;
13681369 if ( m >= entry . length || c !== entry [ m ] ) {
13691370 return first . substring ( 0 , m ) ;
@@ -1506,7 +1507,7 @@ function defineDefaultCommands(repl) {
15061507 }
15071508 } ) ;
15081509
1509- var clearMessage ;
1510+ let clearMessage ;
15101511 if ( repl . useGlobal ) {
15111512 clearMessage = 'Alias for .break' ;
15121513 } else {
@@ -1539,11 +1540,11 @@ function defineDefaultCommands(repl) {
15391540 ( max , name ) => Math . max ( max , name . length ) ,
15401541 0
15411542 ) ;
1542- for ( var n = 0 ; n < names . length ; n ++ ) {
1543- var name = names [ n ] ;
1544- var cmd = this . commands [ name ] ;
1545- var spaces = ' ' . repeat ( longestNameLength - name . length + 3 ) ;
1546- var line = `.${ name } ${ cmd . help ? spaces + cmd . help : '' } \n` ;
1543+ for ( let n = 0 ; n < names . length ; n ++ ) {
1544+ const name = names [ n ] ;
1545+ const cmd = this . commands [ name ] ;
1546+ const spaces = ' ' . repeat ( longestNameLength - name . length + 3 ) ;
1547+ const line = `.${ name } ${ cmd . help ? spaces + cmd . help : '' } \n` ;
15471548 this . outputStream . write ( line ) ;
15481549 }
15491550 this . outputStream . write ( '\nPress ^C to abort current expression, ' +
0 commit comments