| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,11 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | + ArrayFrom, | ||
| 5 | + ArrayPrototypeJoin, | ||
| 6 | + ArrayPrototypePop, | ||
| 7 | + ArrayPrototypePush, | ||
| 8 | + FunctionPrototype, | ||
| 4 | 9 | ObjectKeys, | |
| 5 | 10 | } = primordials; | |
| 6 | 11 | ||
@@ -19,7 +24,7 @@ const parser = acorn.Parser.extend( | |||
| 19 | 24 | staticClassFeatures | |
| 20 | 25 | ); | |
| 21 | 26 | ||
| 22 | - const noop = () => {}; | ||
| 27 | + const noop = FunctionPrototype; | ||
| 23 | 28 | const visitorsWithoutAncestors = { | |
| 24 | 29 | ClassDeclaration(node, state, c) { | |
| 25 | 30 | if (state.ancestors[state.ancestors.length - 2] === state.body) { | |
@@ -76,18 +81,18 @@ for (const nodeType of ObjectKeys(walk.base)) { | |||
| 76 | 81 | visitors[nodeType] = (node, state, c) => { | |
| 77 | 82 | const isNew = node !== state.ancestors[state.ancestors.length - 1]; | |
| 78 | 83 | if (isNew) { | |
| 79 | - state.ancestors.push(node); | ||
| 84 | + ArrayPrototypePush(state.ancestors, node); | ||
| 80 | 85 | } | |
| 81 | 86 | callback(node, state, c); | |
| 82 | 87 | if (isNew) { | |
| 83 | - state.ancestors.pop(); | ||
| 88 | + ArrayPrototypePop(state.ancestors); | ||
| 84 | 89 | } | |
| 85 | 90 | }; | |
| 86 | 91 | } | |
| 87 | 92 | ||
| 88 | 93 | function processTopLevelAwait(src) { | |
| 89 | 94 | const wrapped = `(async () => { ${src} })()`; | |
| 90 | - const wrappedArray = wrapped.split(''); | ||
| 95 | + const wrappedArray = ArrayFrom(wrapped); | ||
| 91 | 96 | let root; | |
| 92 | 97 | try { | |
| 93 | 98 | root = parser.parse(wrapped, { ecmaVersion: 'latest' }); | |
@@ -142,7 +147,7 @@ function processTopLevelAwait(src) { | |||
| 142 | 147 | state.append(last.expression, ')'); | |
| 143 | 148 | } | |
| 144 | 149 | ||
| 145 | - return wrappedArray.join(''); | ||
| 150 | + return ArrayPrototypeJoin(wrappedArray, ''); | ||
| 146 | 151 | } | |
| 147 | 152 | ||
| 148 | 153 | module.exports = { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,11 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | + ArrayPrototypeJoin, | ||
| 4 | 5 | Boolean, | |
| 6 | + FunctionPrototype, | ||
| 7 | + StringPrototypeSplit, | ||
| 8 | + StringPrototypeTrim, | ||
| 5 | 9 | } = primordials; | |
| 6 | 10 | ||
| 7 | 11 | const { Interface } = require('readline'); | |
@@ -13,6 +17,8 @@ let debug = require('internal/util/debuglog').debuglog('repl', (fn) => { | |||
| 13 | 17 | }); | |
| 14 | 18 | const { clearTimeout, setTimeout } = require('timers'); | |
| 15 | 19 | ||
| 20 | + const noop = FunctionPrototype; | ||
| 21 | + | ||
| 16 | 22 | // XXX(chrisdickinson): The 15ms debounce value is somewhat arbitrary. | |
| 17 | 23 | // The debounce is to guard against code pasted into the REPL. | |
| 18 | 24 | const kDebounceHistoryMS = 15; | |
@@ -27,7 +33,7 @@ function _writeToOutput(repl, message) { | |||
| 27 | 33 | function setupHistory(repl, historyPath, ready) { | |
| 28 | 34 | // Empty string disables persistent history | |
| 29 | 35 | if (typeof historyPath === 'string') | |
| 30 | - historyPath = historyPath.trim(); | ||
| 36 | + historyPath = StringPrototypeTrim(historyPath); | ||
| 31 | 37 | ||
| 32 | 38 | if (historyPath === '') { | |
| 33 | 39 | repl._historyPrev = _replHistoryMessage; | |
@@ -84,7 +90,7 @@ function setupHistory(repl, historyPath, ready) { | |||
| 84 | 90 | } | |
| 85 | 91 | ||
| 86 | 92 | if (data) { | |
| 87 | - repl.history = data.split(/[\n\r]+/, repl.historySize); | ||
| 93 | + repl.history = StringPrototypeSplit(data, /[\n\r]+/, repl.historySize); | ||
| 88 | 94 | } else { | |
| 89 | 95 | repl.history = []; | |
| 90 | 96 | } | |
@@ -128,7 +134,7 @@ function setupHistory(repl, historyPath, ready) { | |||
| 128 | 134 | return; | |
| 129 | 135 | } | |
| 130 | 136 | writing = true; | |
| 131 | - const historyData = repl.history.join(os.EOL); | ||
| 137 | + const historyData = ArrayPrototypeJoin(repl.history, os.EOL); | ||
| 132 | 138 | fs.write(repl._historyHandle, historyData, 0, 'utf8', onwritten); | |
| 133 | 139 | } | |
| 134 | 140 | ||
@@ -151,7 +157,7 @@ function setupHistory(repl, historyPath, ready) { | |||
| 151 | 157 | return; | |
| 152 | 158 | } | |
| 153 | 159 | repl.off('line', online); | |
| 154 | - fs.close(repl._historyHandle, () => {}); | ||
| 160 | + fs.close(repl._historyHandle, noop); | ||
| 155 | 161 | } | |
| 156 | 162 | } | |
| 157 | 163 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,23 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | + ArrayPrototypeFilter, | ||
| 5 | + ArrayPrototypeIncludes, | ||
| 6 | + ArrayPrototypeMap, | ||
| 7 | + Boolean, | ||
| 8 | + FunctionPrototypeBind, | ||
| 4 | 9 | MathMin, | |
| 10 | + RegExpPrototypeTest, | ||
| 11 | + SafeSet, | ||
| 5 | 12 | SafeStringIterator, | |
| 6 | - Set, | ||
| 13 | + StringPrototypeEndsWith, | ||
| 14 | + StringPrototypeIndexOf, | ||
| 15 | + StringPrototypeLastIndexOf, | ||
| 16 | + StringPrototypeReplace, | ||
| 17 | + StringPrototypeSlice, | ||
| 18 | + StringPrototypeStartsWith, | ||
| 19 | + StringPrototypeToLowerCase, | ||
| 20 | + StringPrototypeTrim, | ||
| 7 | 21 | Symbol, | |
| 8 | 22 | } = primordials; | |
| 9 | 23 | ||
@@ -60,7 +74,9 @@ function isRecoverableError(e, code) { | |||
| 60 | 74 | // curly brace with parenthesis. Note: only the open parenthesis is added | |
| 61 | 75 | // here as the point is to test for potentially valid but incomplete | |
| 62 | 76 | // expressions. | |
| 63 | - if (/^\s*\{/.test(code) && isRecoverableError(e, `(${code}`)) return true; | ||
| 77 | + if (RegExpPrototypeTest(/^\s*\{/, code) && | ||
| 78 | + isRecoverableError(e, `(${code}`)) | ||
| 79 | + return true; | ||
| 64 | 80 | ||
| 65 | 81 | let recoverable = false; | |
| 66 | 82 | ||
@@ -100,9 +116,11 @@ function isRecoverableError(e, code) { | |||
| 100 | 116 | break; | |
| 101 | 117 | ||
| 102 | 118 | case 'Unterminated string constant': | |
| 103 | - const token = this.input.slice(this.lastTokStart, this.pos); | ||
| 119 | + const token = StringPrototypeSlice(this.input, | ||
| 120 | + this.lastTokStart, this.pos); | ||
| 104 | 121 | // See https://www.ecma-international.org/ecma-262/#sec-line-terminators | |
| 105 | - if (/\\(?:\r\n?|\n|\u2028|\u2029)$/.test(token)) { | ||
| 122 | + if (RegExpPrototypeTest(/\\(?:\r\n?|\n|\u2028|\u2029)$/, | ||
| 123 | + token)) { | ||
| 106 | 124 | recoverable = true; | |
| 107 | 125 | } | |
| 108 | 126 | } | |
@@ -236,15 +254,15 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 236 | 254 | hasCompletions = true; | |
| 237 | 255 | ||
| 238 | 256 | // If there is a common prefix to all matches, then apply that portion. | |
| 239 | - const completions = rawCompletions.filter((e) => e); | ||
| 257 | + const completions = ArrayPrototypeFilter(rawCompletions, Boolean); | ||
| 240 | 258 | const prefix = commonPrefix(completions); | |
| 241 | 259 | ||
| 242 | 260 | // No common prefix found. | |
| 243 | 261 | if (prefix.length <= completeOn.length) { | |
| 244 | 262 | return; | |
| 245 | 263 | } | |
| 246 | 264 | ||
| 247 | - const suffix = prefix.slice(completeOn.length); | ||
| 265 | + const suffix = StringPrototypeSlice(prefix, completeOn.length); | ||
| 248 | 266 | ||
| 249 | 267 | if (insertPreview) { | |
| 250 | 268 | repl._insertString(suffix); | |
@@ -272,16 +290,22 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 272 | 290 | } | |
| 273 | 291 | ||
| 274 | 292 | function isInStrictMode(repl) { | |
| 275 | - return repl.replMode === REPL_MODE_STRICT || process.execArgv | ||
| 276 | - .map((e) => e.toLowerCase().replace(/_/g, '-')) | ||
| 277 | - .includes('--use-strict'); | ||
| 293 | + return repl.replMode === REPL_MODE_STRICT || ArrayPrototypeIncludes( | ||
| 294 | + ArrayPrototypeMap(process.execArgv, | ||
| 295 | + (e) => StringPrototypeReplace( | ||
| 296 | + StringPrototypeToLowerCase(e), | ||
| 297 | + /_/g, | ||
| 298 | + '-' | ||
| 299 | + )), | ||
| 300 | + '--use-strict'); | ||
| 278 | 301 | } | |
| 279 | 302 | ||
| 280 | 303 | // This returns a code preview for arbitrary input code. | |
| 281 | 304 | function getInputPreview(input, callback) { | |
| 282 | 305 | // For similar reasons as `defaultEval`, wrap expressions starting with a | |
| 283 | 306 | // curly brace with parenthesis. | |
| 284 | - if (input.startsWith('{') && !input.endsWith(';') && !wrapped) { | ||
| 307 | + if (StringPrototypeStartsWith(input, '{') && | ||
| 308 | + !StringPrototypeEndsWith(input, ';') && !wrapped) { | ||
| 285 | 309 | input = `(${input})`; | |
| 286 | 310 | wrapped = true; | |
| 287 | 311 | } | |
@@ -347,7 +371,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 347 | 371 | return; | |
| 348 | 372 | } | |
| 349 | 373 | ||
| 350 | - const line = repl.line.trim(); | ||
| 374 | + const line = StringPrototypeTrim(repl.line); | ||
| 351 | 375 | ||
| 352 | 376 | // Do not preview in case the line only contains whitespace. | |
| 353 | 377 | if (line === '') { | |
@@ -413,9 +437,9 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 413 | 437 | ||
| 414 | 438 | // Line breaks are very rare and probably only occur in case of error | |
| 415 | 439 | // messages with line breaks. | |
| 416 | - const lineBreakPos = inspected.indexOf('\n'); | ||
| 440 | + const lineBreakPos = StringPrototypeIndexOf(inspected, '\n'); | ||
| 417 | 441 | if (lineBreakPos !== -1) { | |
| 418 | - inspected = `${inspected.slice(0, lineBreakPos)}`; | ||
| 442 | + inspected = `${StringPrototypeSlice(inspected, 0, lineBreakPos)}`; | ||
| 419 | 443 | } | |
| 420 | 444 | ||
| 421 | 445 | const result = repl.useColors ? | |
@@ -453,7 +477,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 453 | 477 | // Refresh prints the whole screen again and the preview will be removed | |
| 454 | 478 | // during that procedure. Print the preview again. This also makes sure | |
| 455 | 479 | // the preview is always correct after resizing the terminal window. | |
| 456 | - const originalRefresh = repl._refreshLine.bind(repl); | ||
| 480 | + const originalRefresh = FunctionPrototypeBind(repl._refreshLine, repl); | ||
| 457 | 481 | repl._refreshLine = () => { | |
| 458 | 482 | inputPreview = null; | |
| 459 | 483 | originalRefresh(); | |
@@ -463,7 +487,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 463 | 487 | let insertCompletionPreview = true; | |
| 464 | 488 | // Insert the longest common suffix of the current input in case the user | |
| 465 | 489 | // moves to the right while already being at the current input end. | |
| 466 | - const originalMoveCursor = repl._moveCursor.bind(repl); | ||
| 490 | + const originalMoveCursor = FunctionPrototypeBind(repl._moveCursor, repl); | ||
| 467 | 491 | repl._moveCursor = (dx) => { | |
| 468 | 492 | const currentCursor = repl.cursor; | |
| 469 | 493 | originalMoveCursor(dx); | |
@@ -477,7 +501,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 477 | 501 | ||
| 478 | 502 | // This is the only function that interferes with the completion insertion. | |
| 479 | 503 | // Monkey patch it to prevent inserting the completion when it shouldn't be. | |
| 480 | - const originalClearLine = repl.clearLine.bind(repl); | ||
| 504 | + const originalClearLine = FunctionPrototypeBind(repl.clearLine, repl); | ||
| 481 | 505 | repl.clearLine = () => { | |
| 482 | 506 | insertCompletionPreview = false; | |
| 483 | 507 | originalClearLine(); | |
@@ -493,7 +517,7 @@ function setupReverseSearch(repl) { | |||
| 493 | 517 | return { reverseSearch() { return false; } }; | |
| 494 | 518 | } | |
| 495 | 519 | ||
| 496 | - const alreadyMatched = new Set(); | ||
| 520 | + const alreadyMatched = new SafeSet(); | ||
| 497 | 521 | const labels = { | |
| 498 | 522 | r: 'bck-i-search: ', | |
| 499 | 523 | s: 'fwd-i-search: ' | |
@@ -557,18 +581,18 @@ function setupReverseSearch(repl) { | |||
| 557 | 581 | if (cursor === -1) { | |
| 558 | 582 | cursor = entry.length; | |
| 559 | 583 | } | |
| 560 | - cursor = entry.lastIndexOf(input, cursor - 1); | ||
| 584 | + cursor = StringPrototypeLastIndexOf(entry, input, cursor - 1); | ||
| 561 | 585 | } else { | |
| 562 | - cursor = entry.indexOf(input, cursor + 1); | ||
| 586 | + cursor = StringPrototypeIndexOf(entry, input, cursor + 1); | ||
| 563 | 587 | } | |
| 564 | 588 | // Match not found. | |
| 565 | 589 | if (cursor === -1) { | |
| 566 | 590 | goToNextHistoryIndex(); | |
| 567 | 591 | // Match found. | |
| 568 | 592 | } else { | |
| 569 | 593 | if (repl.useColors) { | |
| 570 | - const start = entry.slice(0, cursor); | ||
| 571 | - const end = entry.slice(cursor + input.length); | ||
| 594 | + const start = StringPrototypeSlice(entry, 0, cursor); | ||
| 595 | + const end = StringPrototypeSlice(entry, cursor + input.length); | ||
| 572 | 596 | entry = `${start}\x1B[4m${input}\x1B[24m${end}`; | |
| 573 | 597 | } | |
| 574 | 598 | print(entry, `${labels[dir]}${input}_`, cursor); | |
@@ -611,7 +635,7 @@ function setupReverseSearch(repl) { | |||
| 611 | 635 | // tick end instead of after each operation. | |
| 612 | 636 | let rows = 0; | |
| 613 | 637 | if (lastMatch !== -1) { | |
| 614 | - const line = repl.history[lastMatch].slice(0, lastCursor); | ||
| 638 | + const line = StringPrototypeSlice(repl.history[lastMatch], 0, lastCursor); | ||
| 615 | 639 | rows = repl._getDisplayPos(`${repl.getPrompt()}${line}`).rows; | |
| 616 | 640 | cursorTo(repl.output, promptPos.cols); | |
| 617 | 641 | } else if (isInReverseSearch && repl.line !== '') { | |
@@ -633,7 +657,7 @@ function setupReverseSearch(repl) { | |||
| 633 | 657 | // To know exactly how many rows we have to move the cursor back we need the | |
| 634 | 658 | // cursor rows, the output rows and the input rows. | |
| 635 | 659 | const prompt = repl.getPrompt(); | |
| 636 | - const cursorLine = `${prompt}${outputLine.slice(0, cursor)}`; | ||
| 660 | + const cursorLine = prompt + StringPrototypeSlice(outputLine, 0, cursor); | ||
| 637 | 661 | const cursorPos = repl._getDisplayPos(cursorLine); | |
| 638 | 662 | const outputPos = repl._getDisplayPos(`${prompt}${outputLine}`); | |
| 639 | 663 | const inputPos = repl._getDisplayPos(inputLine); | |
@@ -691,7 +715,7 @@ function setupReverseSearch(repl) { | |||
| 691 | 715 | search(); | |
| 692 | 716 | } else if (key.name === 'backspace' || | |
| 693 | 717 | (key.ctrl && (key.name === 'h' || key.name === 'w'))) { | |
| 694 | - reset(input.slice(0, input.length - 1)); | ||
| 718 | + reset(StringPrototypeSlice(input, 0, input.length - 1)); | ||
| 695 | 719 | search(); | |
| 696 | 720 | // Special handle <ctrl> + c and escape. Those should only cancel the | |
| 697 | 721 | // reverse search. The original line is visible afterwards again. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments