Skip to content

Commit ca79fc5

Browse files
jvelezpoBridgeAR
authored andcommitted
src: replace var for (let|const) in utilities module
Update Utilities module to replace var for let or const PR-URL: #18814 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matheus Marchini <matheus@sthima.com>
1 parent 6aab9e1 commit ca79fc5

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

lib/internal/util.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function deprecate(fn, msg, code) {
4747
if (code !== undefined && typeof code !== 'string')
4848
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'code', 'string');
4949

50-
var warned = false;
50+
let warned = false;
5151
function deprecated(...args) {
5252
if (!warned) {
5353
warned = true;
@@ -103,7 +103,7 @@ function assertCrypto() {
103103
// Return undefined if there is no match.
104104
function normalizeEncoding(enc) {
105105
if (!enc) return 'utf8';
106-
var retried;
106+
let retried;
107107
while (true) {
108108
switch (enc) {
109109
case 'utf8':
@@ -152,7 +152,7 @@ function filterDuplicateStrings(items, low) {
152152
}
153153

154154
function cachedResult(fn) {
155-
var result;
155+
let result;
156156
return () => {
157157
if (result === undefined)
158158
result = fn();
@@ -207,7 +207,7 @@ function convertToValidSignal(signal) {
207207

208208
function getConstructorOf(obj) {
209209
while (obj) {
210-
var descriptor = Object.getOwnPropertyDescriptor(obj, 'constructor');
210+
const descriptor = Object.getOwnPropertyDescriptor(obj, 'constructor');
211211
if (descriptor !== undefined &&
212212
typeof descriptor.value === 'function' &&
213213
descriptor.value.name !== '') {
@@ -323,7 +323,7 @@ promisify.custom = kCustomPromisifiedSymbol;
323323

324324
// The build-in Array#join is slower in v8 6.0
325325
function join(output, separator) {
326-
var str = '';
326+
let str = '';
327327
if (output.length !== 0) {
328328
for (var i = 0; i < output.length - 1; i++) {
329329
// It is faster not to use a template string here

lib/util.js

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const regExpToString = RegExp.prototype.toString;
7979
const dateToISOString = Date.prototype.toISOString;
8080
const errorToString = Error.prototype.toString;
8181

82-
var CIRCULAR_ERROR_MESSAGE;
82+
let CIRCULAR_ERROR_MESSAGE;
8383

8484
/* eslint-disable */
8585
const strEscapeSequencesRegExp = /[\x00-\x1f\x27\x5c]/;
@@ -119,8 +119,8 @@ function strEscape(str) {
119119
return `'${str}'`;
120120
if (str.length > 100)
121121
return `'${str.replace(strEscapeSequencesReplacer, escapeFn)}'`;
122-
var result = '';
123-
var last = 0;
122+
let result = '';
123+
let last = 0;
124124
for (var i = 0; i < str.length; i++) {
125125
const point = str.charCodeAt(i);
126126
if (point === 39 || point === 92 || point < 32) {
@@ -159,10 +159,10 @@ function tryStringify(arg) {
159159
}
160160

161161
function format(f) {
162-
var i, tempStr;
162+
let i, tempStr;
163163
if (typeof f !== 'string') {
164164
if (arguments.length === 0) return '';
165-
var res = '';
165+
let res = '';
166166
for (i = 0; i < arguments.length - 1; i++) {
167167
res += inspect(arguments[i]);
168168
res += ' ';
@@ -173,9 +173,9 @@ function format(f) {
173173

174174
if (arguments.length === 1) return f;
175175

176-
var str = '';
177-
var a = 1;
178-
var lastPos = 0;
176+
let str = '';
177+
let a = 1;
178+
let lastPos = 0;
179179
for (i = 0; i < f.length - 1; i++) {
180180
if (f.charCodeAt(i) === 37) { // '%'
181181
const nextChar = f.charCodeAt(++i);
@@ -250,9 +250,9 @@ function debuglog(set) {
250250
set = set.toUpperCase();
251251
if (!debugs[set]) {
252252
if (debugEnvRegex.test(set)) {
253-
var pid = process.pid;
253+
const pid = process.pid;
254254
debugs[set] = function() {
255-
var msg = exports.format.apply(exports, arguments);
255+
const msg = exports.format.apply(exports, arguments);
256256
console.error('%s %d: %s', set, pid, msg);
257257
};
258258
} else {
@@ -426,8 +426,8 @@ function formatValue(ctx, value, recurseTimes, ln) {
426426
}
427427
}
428428

429-
var keys;
430-
var symbols = Object.getOwnPropertySymbols(value);
429+
let keys;
430+
let symbols = Object.getOwnPropertySymbols(value);
431431

432432
// Look up the keys of the object.
433433
if (ctx.showHidden) {
@@ -441,19 +441,19 @@ function formatValue(ctx, value, recurseTimes, ln) {
441441
const keyLength = keys.length + symbols.length;
442442

443443
const { constructor, tag } = getIdentificationOf(value);
444-
var prefix = '';
444+
let prefix = '';
445445
if (constructor && tag && constructor !== tag)
446446
prefix = `${constructor} [${tag}] `;
447447
else if (constructor)
448448
prefix = `${constructor} `;
449449
else if (tag)
450450
prefix = `[${tag}] `;
451451

452-
var base = '';
453-
var formatter = formatObject;
454-
var braces;
455-
var noIterator = true;
456-
var raw;
452+
let base = '';
453+
let formatter = formatObject;
454+
let braces;
455+
let noIterator = true;
456+
let raw;
457457

458458
// Iterators and the rest are split to reduce checks
459459
if (value[Symbol.iterator]) {
@@ -623,7 +623,7 @@ function formatPrimitive(fn, value, ctx) {
623623
// eslint-disable-next-line max-len
624624
const averageLineLength = Math.ceil(value.length / Math.ceil(value.length / minLineLength));
625625
const divisor = Math.max(averageLineLength, MIN_LINE_LENGTH);
626-
var res = '';
626+
let res = '';
627627
if (readableRegExps[divisor] === undefined) {
628628
// Build a new RegExp that naturally breaks text into multiple lines.
629629
//
@@ -678,8 +678,8 @@ function formatObject(ctx, value, recurseTimes, keys) {
678678
function formatSpecialArray(ctx, value, recurseTimes, keys, maxLength, valLen) {
679679
const output = [];
680680
const keyLen = keys.length;
681-
var visibleLength = 0;
682-
var i = 0;
681+
let visibleLength = 0;
682+
let i = 0;
683683
if (keyLen !== 0 && numberRegExp.test(keys[0])) {
684684
for (const key of keys) {
685685
if (visibleLength === maxLength)
@@ -728,7 +728,7 @@ function formatSpecialArray(ctx, value, recurseTimes, keys, maxLength, valLen) {
728728
} else if (keys[keyLen - 1] !== `${valLen - 1}`) {
729729
const extra = [];
730730
// Only handle special keys
731-
var key;
731+
let key;
732732
for (i = keys.length - 1; i >= 0; i--) {
733733
key = keys[i];
734734
if (numberRegExp.test(key) && +key < 2 ** 32 - 1)
@@ -792,7 +792,7 @@ function formatTypedArray(ctx, value, recurseTimes, keys) {
792792

793793
function formatSet(ctx, value, recurseTimes, keys) {
794794
const output = new Array(value.size + keys.length + (ctx.showHidden ? 1 : 0));
795-
var i = 0;
795+
let i = 0;
796796
for (const v of value)
797797
output[i++] = formatValue(ctx, v, recurseTimes);
798798
// With `showHidden`, `length` will display as a hidden property for
@@ -808,7 +808,7 @@ function formatSet(ctx, value, recurseTimes, keys) {
808808

809809
function formatMap(ctx, value, recurseTimes, keys) {
810810
const output = new Array(value.size + keys.length + (ctx.showHidden ? 1 : 0));
811-
var i = 0;
811+
let i = 0;
812812
for (const [k, v] of value)
813813
output[i++] = `${formatValue(ctx, k, recurseTimes)} => ` +
814814
formatValue(ctx, v, recurseTimes);
@@ -823,9 +823,9 @@ function formatMap(ctx, value, recurseTimes, keys) {
823823

824824
function formatCollectionIterator(preview, ctx, value, recurseTimes,
825825
visibleKeys, keys) {
826-
var nextRecurseTimes = recurseTimes === null ? null : recurseTimes - 1;
827-
var vals = preview(value, 100);
828-
var output = [];
826+
const nextRecurseTimes = recurseTimes === null ? null : recurseTimes - 1;
827+
const vals = preview(value, 100);
828+
const output = [];
829829
for (const o of vals) {
830830
output.push(formatValue(ctx, o, nextRecurseTimes));
831831
}
@@ -843,7 +843,7 @@ function formatSetIterator(ctx, value, recurseTimes, visibleKeys, keys) {
843843
}
844844

845845
function formatPromise(ctx, value, recurseTimes, keys) {
846-
var output;
846+
let output;
847847
const [state, result] = getPromiseDetails(value);
848848
if (state === kPending) {
849849
output = ['<pending>'];
@@ -858,7 +858,7 @@ function formatPromise(ctx, value, recurseTimes, keys) {
858858
}
859859

860860
function formatProperty(ctx, value, recurseTimes, key, array) {
861-
var name, str;
861+
let name, str;
862862
const desc = Object.getOwnPropertyDescriptor(value, key) ||
863863
{ value: value[key], enumerable: true };
864864
if (desc.value !== undefined) {
@@ -895,18 +895,18 @@ function formatProperty(ctx, value, recurseTimes, key, array) {
895895

896896
function reduceToSingleString(ctx, output, base, braces, addLn) {
897897
const breakLength = ctx.breakLength;
898-
var i = 0;
898+
let i = 0;
899899
if (ctx.compact === false) {
900900
const indentation = ' '.repeat(ctx.indentationLvl);
901-
var res = `${base ? `${base} ` : ''}${braces[0]}\n${indentation} `;
901+
let res = `${base ? `${base} ` : ''}${braces[0]}\n${indentation} `;
902902
for (; i < output.length - 1; i++) {
903903
res += `${output[i]},\n${indentation} `;
904904
}
905905
res += `${output[i]}\n${indentation}${braces[1]}`;
906906
return res;
907907
}
908908
if (output.length * 2 <= breakLength) {
909-
var length = 0;
909+
let length = 0;
910910
for (; i < output.length && length <= breakLength; i++) {
911911
if (ctx.colors) {
912912
length += removeColors(output[i]).length + 1;
@@ -979,10 +979,10 @@ const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
979979

980980
// 26 Feb 16:19:34
981981
function timestamp() {
982-
var d = new Date();
983-
var time = [pad(d.getHours()),
984-
pad(d.getMinutes()),
985-
pad(d.getSeconds())].join(':');
982+
const d = new Date();
983+
const time = [pad(d.getHours()),
984+
pad(d.getMinutes()),
985+
pad(d.getSeconds())].join(':');
986986
return [d.getDate(), months[d.getMonth()], time].join(' ');
987987
}
988988

@@ -1026,8 +1026,8 @@ function _extend(target, source) {
10261026
// Don't do anything if source isn't an object
10271027
if (source === null || typeof source !== 'object') return target;
10281028

1029-
var keys = Object.keys(source);
1030-
var i = keys.length;
1029+
const keys = Object.keys(source);
1030+
let i = keys.length;
10311031
while (i--) {
10321032
target[keys[i]] = source[keys[i]];
10331033
}

0 commit comments

Comments
 (0)