Skip to content

Commit 95ba482

Browse files
author
Myles Borins
committed
meta: remove let from for loops
This is a known de-opt. It may not be 100% necessary in all cases but it seems like a decent enough idea to avoid it. PR-URL: #8873 Reviewed-By: Brian White <[email protected]> Reviewed-By: Ilkka Myller <[email protected]> Reviewed-By: Johan Bergström <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 7420835 commit 95ba482

File tree

8 files changed

+13
-13
lines changed

8 files changed

+13
-13
lines changed

lib/_stream_readable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ Readable.prototype.unpipe = function(dest) {
661661
state.pipesCount = 0;
662662
state.flowing = false;
663663

664-
for (let i = 0; i < len; i++)
664+
for (var i = 0; i < len; i++)
665665
dests[i].emit('unpipe', this);
666666
return this;
667667
}

lib/internal/readline.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function getStringWidth(str) {
2626

2727
str = stripVTControlCharacters(str);
2828

29-
for (let i = 0; i < str.length; i++) {
29+
for (var i = 0; i < str.length; i++) {
3030
const code = str.codePointAt(i);
3131

3232
if (code >= 0x10000) { // surrogates

lib/internal/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ exports.error = function(msg) {
2424
if (arguments.length > 1) {
2525
const args = new Array(arguments.length);
2626
args[0] = fmt;
27-
for (let i = 1; i < arguments.length; ++i)
27+
for (var i = 1; i < arguments.length; ++i)
2828
args[i] = arguments[i];
2929
console.error.apply(console, args);
3030
} else {

lib/punycode.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ const decode = function(input) {
210210
basic = 0;
211211
}
212212

213-
for (let j = 0; j < basic; ++j) {
213+
for (var j = 0; j < basic; ++j) {
214214
// if it's not a basic code point
215215
if (input.charCodeAt(j) >= 0x80) {
216216
error('not-basic');
@@ -221,15 +221,15 @@ const decode = function(input) {
221221
// Main decoding loop: start just after the last delimiter if any basic code
222222
// points were copied; start at the beginning otherwise.
223223

224-
for (let index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
224+
for (var index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
225225

226226
// `index` is the index of the next character to be consumed.
227227
// Decode a generalized variable-length integer into `delta`,
228228
// which gets added to `i`. The overflow checking is easier
229229
// if we increase `i` as we go, then subtract off its starting
230230
// value at the end to obtain `delta`.
231231
let oldi = i;
232-
for (let w = 1, k = base; /* no condition */; k += base) {
232+
for (var w = 1, k = base; /* no condition */; k += base) {
233233

234234
if (index >= inputLength) {
235235
error('invalid-input');
@@ -345,7 +345,7 @@ const encode = function(input) {
345345
if (currentValue == n) {
346346
// Represent delta as a generalized variable-length integer.
347347
let q = delta;
348-
for (let k = base; /* no condition */; k += base) {
348+
for (var k = base; /* no condition */; k += base) {
349349
const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
350350
if (q < t) {
351351
break;

lib/repl.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ function REPLServer(prompt,
345345

346346
// After executing the current expression, store the values of RegExp
347347
// predefined properties back in `savedRegExMatches`
348-
for (let idx = 1; idx < savedRegExMatches.length; idx += 1) {
348+
for (var idx = 1; idx < savedRegExMatches.length; idx += 1) {
349349
savedRegExMatches[idx] = RegExp[`$${idx}`];
350350
}
351351

@@ -1078,9 +1078,9 @@ function longestCommonPrefix(arr = []) {
10781078

10791079
const first = arr[0];
10801080
// complexity: O(m * n)
1081-
for (let m = 0; m < first.length; m++) {
1081+
for (var m = 0; m < first.length; m++) {
10821082
const c = first[m];
1083-
for (let n = 1; n < cnt; n++) {
1083+
for (var n = 1; n < cnt; n++) {
10841084
const entry = arr[n];
10851085
if (m >= entry.length || c !== entry[m]) {
10861086
return first.substring(0, m);

lib/tls.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function check(hostParts, pattern, wildcards) {
100100
return false;
101101

102102
// Check host parts from right to left first.
103-
for (let i = hostParts.length - 1; i > 0; i -= 1)
103+
for (var i = hostParts.length - 1; i > 0; i -= 1)
104104
if (hostParts[i] !== patternParts[i])
105105
return false;
106106

lib/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if (typeof global.SIMD === 'object' && global.SIMD !== null) {
3030
const make = (extractLane, count) => {
3131
return (ctx, value, recurseTimes, visibleKeys, keys) => {
3232
const output = new Array(count);
33-
for (let i = 0; i < count; i += 1)
33+
for (var i = 0; i < count; i += 1)
3434
output[i] = formatPrimitive(ctx, extractLane(value, i));
3535
return output;
3636
};

lib/v8.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ exports.getHeapSpaceStatistics = function() {
6060
const buffer = heapSpaceStatisticsBuffer;
6161
v8binding.updateHeapSpaceStatisticsArrayBuffer();
6262

63-
for (let i = 0; i < kNumberOfHeapSpaces; i++) {
63+
for (var i = 0; i < kNumberOfHeapSpaces; i++) {
6464
const propertyOffset = i * kHeapSpaceStatisticsPropertiesCount;
6565
heapSpaceStatistics[i] = {
6666
space_name: kHeapSpaces[i],

0 commit comments

Comments
 (0)