| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bc3c0b2 commit a5bd7e3
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ | |||
| 22 | 22 | /* A repl library that you can include in your own code to get a runtime | |
| 23 | 23 | * interface to your program. | |
| 24 | 24 | * | |
| 25 | - * var repl = require("repl"); | ||
| 25 | + * const repl = require("repl"); | ||
| 26 | 26 | * // start repl on stdin | |
| 27 | 27 | * repl.start("prompt> "); | |
| 28 | 28 | * | |
@@ -372,7 +372,7 @@ function REPLServer(prompt, | |||
| 372 | 372 | ||
| 373 | 373 | // After executing the current expression, store the values of RegExp | |
| 374 | 374 | // 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) { | ||
| 376 | 376 | savedRegExMatches[idx] = RegExp[`$${idx}`]; | |
| 377 | 377 | } | |
| 378 | 378 | ||
@@ -636,8 +636,8 @@ function REPLServer(prompt, | |||
| 636 | 636 | self.emit('exit'); | |
| 637 | 637 | }); | |
| 638 | 638 | ||
| 639 | - var sawSIGINT = false; | ||
| 640 | - var sawCtrlD = false; | ||
| 639 | + let sawSIGINT = false; | ||
| 640 | + let sawCtrlD = false; | ||
| 641 | 641 | const prioritizedSigintQueue = new Set(); | |
| 642 | 642 | self.on('SIGINT', function onSigInt() { | |
| 643 | 643 | if (prioritizedSigintQueue.size > 0) { | |
@@ -877,7 +877,7 @@ REPLServer.prototype.close = function close() { | |||
| 877 | 877 | }; | |
| 878 | 878 | ||
| 879 | 879 | REPLServer.prototype.createContext = function() { | |
| 880 | - var context; | ||
| 880 | + let context; | ||
| 881 | 881 | if (this.useGlobal) { | |
| 882 | 882 | context = global; | |
| 883 | 883 | } else { | |
@@ -963,7 +963,7 @@ REPLServer.prototype.resetContext = function() { | |||
| 963 | 963 | }; | |
| 964 | 964 | ||
| 965 | 965 | REPLServer.prototype.displayPrompt = function(preserveCursor) { | |
| 966 | - var prompt = this._initialPrompt; | ||
| 966 | + let prompt = this._initialPrompt; | ||
| 967 | 967 | if (this[kBufferedCommandSymbol].length) { | |
| 968 | 968 | prompt = '...'; | |
| 969 | 969 | const len = this.lines.level.length ? this.lines.level.length - 1 : 0; | |
@@ -993,7 +993,7 @@ function ArrayStream() { | |||
| 993 | 993 | Stream.call(this); | |
| 994 | 994 | ||
| 995 | 995 | this.run = function(data) { | |
| 996 | - for (var n = 0; n < data.length; n++) | ||
| 996 | + for (let n = 0; n < data.length; n++) | ||
| 997 | 997 | this.emit('data', `${data[n]}\n`); | |
| 998 | 998 | }; | |
| 999 | 999 | } | |
@@ -1018,7 +1018,7 @@ function isIdentifier(str) { | |||
| 1018 | 1018 | return false; | |
| 1019 | 1019 | } | |
| 1020 | 1020 | 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) { | ||
| 1022 | 1022 | const cp = str.codePointAt(i); | |
| 1023 | 1023 | if (!isIdentifierChar(cp)) { | |
| 1024 | 1024 | return false; | |
@@ -1056,7 +1056,7 @@ REPLServer.prototype.complete = function() { | |||
| 1056 | 1056 | // given to the readline interface for handling tab completion. | |
| 1057 | 1057 | // | |
| 1058 | 1058 | // Example: | |
| 1059 | - // complete('var foo = util.') | ||
| 1059 | + // complete('let foo = util.') | ||
| 1060 | 1060 | // -> [['util.print', 'util.debug', 'util.log', 'util.inspect'], | |
| 1061 | 1061 | // 'util.' ] | |
| 1062 | 1062 | // | |
@@ -1067,16 +1067,16 @@ function complete(line, callback) { | |||
| 1067 | 1067 | if (this[kBufferedCommandSymbol] !== undefined && | |
| 1068 | 1068 | this[kBufferedCommandSymbol].length) { | |
| 1069 | 1069 | // Get a new array of inputted lines | |
| 1070 | - var tmp = this.lines.slice(); | ||
| 1070 | + const tmp = this.lines.slice(); | ||
| 1071 | 1071 | // Kill off all function declarations to push all local variables into | |
| 1072 | 1072 | // 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]; | ||
| 1075 | 1075 | if (kill.isFunction) | |
| 1076 | 1076 | tmp[kill.line] = ''; | |
| 1077 | 1077 | } | |
| 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. | ||
| 1080 | 1080 | replMap.set(magic, replMap.get(this)); | |
| 1081 | 1081 | flat.run(tmp); // `eval` the flattened code. | |
| 1082 | 1082 | // All this is only profitable if the nested REPL does not have a | |
@@ -1087,13 +1087,12 @@ function complete(line, callback) { | |||
| 1087 | 1087 | } | |
| 1088 | 1088 | } | |
| 1089 | 1089 | ||
| 1090 | - var completions; | ||
| 1091 | 1090 | // List of completion lists, one for each inheritance "level" | |
| 1092 | - var completionGroups = []; | ||
| 1093 | - var completeOn, group, c; | ||
| 1091 | + let completionGroups = []; | ||
| 1092 | + let completeOn, group; | ||
| 1094 | 1093 | ||
| 1095 | 1094 | // REPL commands (e.g. ".break"). | |
| 1096 | - var filter; | ||
| 1095 | + let filter; | ||
| 1097 | 1096 | let match = line.match(/^\s*\.(\w*)$/); | |
| 1098 | 1097 | if (match) { | |
| 1099 | 1098 | completionGroups.push(Object.keys(this.commands)); | |
@@ -1106,14 +1105,14 @@ function complete(line, callback) { | |||
| 1106 | 1105 | } else if (match = line.match(requireRE)) { | |
| 1107 | 1106 | // require('...<Tab>') | |
| 1108 | 1107 | 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('|') + | ||
| 1110 | 1109 | ')$'); | |
| 1111 | - var versionedFileNamesRe = /-\d+\.\d+/; | ||
| 1110 | + const versionedFileNamesRe = /-\d+\.\d+/; | ||
| 1112 | 1111 | ||
| 1113 | 1112 | completeOn = match[1]; | |
| 1114 | - var subdir = match[2] || ''; | ||
| 1113 | + const subdir = match[2] || ''; | ||
| 1115 | 1114 | filter = match[1]; | |
| 1116 | - var dir, files, name, base, ext, abs, subfiles, isDirectory; | ||
| 1115 | + let dir, files, name, base, ext, abs, subfiles, isDirectory; | ||
| 1117 | 1116 | group = []; | |
| 1118 | 1117 | let paths = []; | |
| 1119 | 1118 | ||
@@ -1211,7 +1210,7 @@ function complete(line, callback) { | |||
| 1211 | 1210 | } else if (line.length === 0 || /\w|\.|\$/.test(line[line.length - 1])) { | |
| 1212 | 1211 | match = simpleExpressionRE.exec(line); | |
| 1213 | 1212 | if (line.length === 0 || match) { | |
| 1214 | - var expr; | ||
| 1213 | + let expr; | ||
| 1215 | 1214 | completeOn = (match ? match[0] : ''); | |
| 1216 | 1215 | if (line.length === 0) { | |
| 1217 | 1216 | filter = ''; | |
@@ -1220,19 +1219,19 @@ function complete(line, callback) { | |||
| 1220 | 1219 | filter = ''; | |
| 1221 | 1220 | expr = match[0].slice(0, match[0].length - 1); | |
| 1222 | 1221 | } else { | |
| 1223 | - var bits = match[0].split('.'); | ||
| 1222 | + const bits = match[0].split('.'); | ||
| 1224 | 1223 | filter = bits.pop(); | |
| 1225 | 1224 | expr = bits.join('.'); | |
| 1226 | 1225 | } | |
| 1227 | 1226 | ||
| 1228 | 1227 | // Resolve expr and get its completions. | |
| 1229 | - var memberGroups = []; | ||
| 1228 | + const memberGroups = []; | ||
| 1230 | 1229 | if (!expr) { | |
| 1231 | 1230 | // If context is instance of vm.ScriptContext | |
| 1232 | 1231 | // Get global vars synchronously | |
| 1233 | 1232 | if (this.useGlobal || vm.isContext(this.context)) { | |
| 1234 | 1233 | completionGroups.push(getGlobalLexicalScopeNames(this[kContextId])); | |
| 1235 | - var contextProto = this.context; | ||
| 1234 | + let contextProto = this.context; | ||
| 1236 | 1235 | while (contextProto = Object.getPrototypeOf(contextProto)) { | |
| 1237 | 1236 | completionGroups.push( | |
| 1238 | 1237 | filteredOwnPropertyNames.call(this, contextProto)); | |
@@ -1247,7 +1246,7 @@ function complete(line, callback) { | |||
| 1247 | 1246 | if (filter !== '') addCommonWords(completionGroups); | |
| 1248 | 1247 | } else if (Array.isArray(globals[0])) { | |
| 1249 | 1248 | // Add grouped globals | |
| 1250 | - for (var n = 0; n < globals.length; n++) | ||
| 1249 | + for (let n = 0; n < globals.length; n++) | ||
| 1251 | 1250 | completionGroups.push(globals[n]); | |
| 1252 | 1251 | } else { | |
| 1253 | 1252 | completionGroups.push(globals); | |
@@ -1272,8 +1271,8 @@ function complete(line, callback) { | |||
| 1272 | 1271 | } | |
| 1273 | 1272 | // Works for non-objects | |
| 1274 | 1273 | try { | |
| 1275 | - var sentinel = 5; | ||
| 1276 | - var p; | ||
| 1274 | + let sentinel = 5; | ||
| 1275 | + let p; | ||
| 1277 | 1276 | if (typeof obj === 'object' || typeof obj === 'function') { | |
| 1278 | 1277 | p = Object.getPrototypeOf(obj); | |
| 1279 | 1278 | } else { | |
@@ -1316,7 +1315,7 @@ function complete(line, callback) { | |||
| 1316 | 1315 | function completionGroupsLoaded() { | |
| 1317 | 1316 | // Filter, sort (within each group), uniq and merge the completion groups. | |
| 1318 | 1317 | if (completionGroups.length && filter) { | |
| 1319 | - var newCompletionGroups = []; | ||
| 1318 | + const newCompletionGroups = []; | ||
| 1320 | 1319 | for (let i = 0; i < completionGroups.length; i++) { | |
| 1321 | 1320 | group = completionGroups[i] | |
| 1322 | 1321 | .filter((elem) => elem.indexOf(filter) === 0); | |
@@ -1327,17 +1326,19 @@ function complete(line, callback) { | |||
| 1327 | 1326 | completionGroups = newCompletionGroups; | |
| 1328 | 1327 | } | |
| 1329 | 1328 | ||
| 1329 | + let completions; | ||
| 1330 | + | ||
| 1330 | 1331 | if (completionGroups.length) { | |
| 1331 | - var uniq = {}; // Unique completions across all groups | ||
| 1332 | + const uniq = {}; // Unique completions across all groups | ||
| 1332 | 1333 | completions = []; | |
| 1333 | 1334 | // Completion group 0 is the "closest" | |
| 1334 | 1335 | // (least far up the inheritance chain) | |
| 1335 | 1336 | // so we put its completions last: to be closest in the REPL. | |
| 1336 | 1337 | for (let i = 0; i < completionGroups.length; i++) { | |
| 1337 | 1338 | group = completionGroups[i]; | |
| 1338 | 1339 | 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]; | ||
| 1341 | 1342 | if (!ObjectPrototype.hasOwnProperty(uniq, c)) { | |
| 1342 | 1343 | completions.unshift(c); | |
| 1343 | 1344 | uniq[c] = true; | |
@@ -1361,9 +1362,9 @@ function longestCommonPrefix(arr = []) { | |||
| 1361 | 1362 | ||
| 1362 | 1363 | const first = arr[0]; | |
| 1363 | 1364 | // complexity: O(m * n) | |
| 1364 | - for (var m = 0; m < first.length; m++) { | ||
| 1365 | + for (let m = 0; m < first.length; m++) { | ||
| 1365 | 1366 | const c = first[m]; | |
| 1366 | - for (var n = 1; n < cnt; n++) { | ||
| 1367 | + for (let n = 1; n < cnt; n++) { | ||
| 1367 | 1368 | const entry = arr[n]; | |
| 1368 | 1369 | if (m >= entry.length || c !== entry[m]) { | |
| 1369 | 1370 | return first.substring(0, m); | |
@@ -1506,7 +1507,7 @@ function defineDefaultCommands(repl) { | |||
| 1506 | 1507 | } | |
| 1507 | 1508 | }); | |
| 1508 | 1509 | ||
| 1509 | - var clearMessage; | ||
| 1510 | + let clearMessage; | ||
| 1510 | 1511 | if (repl.useGlobal) { | |
| 1511 | 1512 | clearMessage = 'Alias for .break'; | |
| 1512 | 1513 | } else { | |
@@ -1539,11 +1540,11 @@ function defineDefaultCommands(repl) { | |||
| 1539 | 1540 | (max, name) => Math.max(max, name.length), | |
| 1540 | 1541 | 0 | |
| 1541 | 1542 | ); | |
| 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`; | ||
| 1547 | 1548 | this.outputStream.write(line); | |
| 1548 | 1549 | } | |
| 1549 | 1550 | this.outputStream.write('\nPress ^C to abort current expression, ' + | |
| Back | FazBrowse Home | New Git URL |
0 commit comments