Skip to content

Commit 163d306

Browse files
aduh95targos
authored andcommitted
lib: remove use of array destructuring
PR-URL: nodejs#36818 Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 3d7fe14 commit 163d306

17 files changed

+43
-39
lines changed

lib/_http_server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ Server.prototype.setTimeout = function setTimeout(msecs, callback) {
395395
Server.prototype[EE.captureRejectionSymbol] = function(err, event, ...args) {
396396
switch (event) {
397397
case 'request':
398-
const [ , res] = args;
398+
const { 1: res } = args;
399399
if (!res.headersSent && !res.writableEnded) {
400400
// Don't leak headers.
401401
const names = res.getHeaderNames();

lib/assert.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,15 @@ function getErrMessage(message, fn) {
339339
}
340340
fd = openSync(filename, 'r', 0o666);
341341
// Reset column and message.
342-
[column, message] = getCode(fd, line, column);
342+
({ 0: column, 1: message } = getCode(fd, line, column));
343343
// Flush unfinished multi byte characters.
344344
decoder.end();
345345
} else {
346346
for (let i = 0; i < line; i++) {
347347
code = StringPrototypeSlice(code,
348348
StringPrototypeIndexOf(code, '\n') + 1);
349349
}
350-
[column, message] = parseCode(code, column);
350+
({ 0: column, 1: message } = parseCode(code, column));
351351
}
352352
// Always normalize indentation, otherwise the message could look weird.
353353
if (StringPrototypeIncludes(message, '\n')) {

lib/events.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ function enhanceStackTrace(err, own) {
330330
const errStack = err.stack.split('\n').slice(1);
331331
const ownStack = own.stack.split('\n').slice(1);
332332

333-
const [ len, off ] = identicalSequenceRange(ownStack, errStack);
333+
const { 0: len, 1: off } = identicalSequenceRange(ownStack, errStack);
334334
if (len > 0) {
335335
ownStack.splice(off + 1, len - 2,
336336
' [... lines matching original stack trace ...]');

lib/fs.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2066,7 +2066,8 @@ function copyFileSync(src, dest, mode) {
20662066
function lazyLoadStreams() {
20672067
if (!ReadStream) {
20682068
({ ReadStream, WriteStream } = require('internal/fs/streams'));
2069-
[ FileReadStream, FileWriteStream ] = [ ReadStream, WriteStream ];
2069+
FileReadStream = ReadStream;
2070+
FileWriteStream = WriteStream;
20702071
}
20712072
}
20722073

lib/internal/bootstrap/loaders.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class NativeModule {
199199
// To be called during pre-execution when --expose-internals is on.
200200
// Enables the user-land module loader to access internal modules.
201201
static exposeInternals() {
202-
for (const [id, mod] of NativeModule.map) {
202+
for (const { 0: id, 1: mod } of NativeModule.map) {
203203
// Do not expose this to user land even with --expose-internals.
204204
if (id !== loaderId) {
205205
mod.canBeRequiredByUsers = true;

lib/internal/cluster/round_robin_handle.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,11 @@ RoundRobinHandle.prototype.remove = function(worker) {
9393

9494
RoundRobinHandle.prototype.distribute = function(err, handle) {
9595
ArrayPrototypePush(this.handles, handle);
96-
const [ workerEntry ] = this.free;
96+
// eslint-disable-next-line node-core/no-array-destructuring
97+
const [ workerEntry ] = this.free; // this.free is a SafeMap
9798

9899
if (ArrayIsArray(workerEntry)) {
99-
const [ workerId, worker ] = workerEntry;
100+
const { 0: workerId, 1: worker } = workerEntry;
100101
this.free.delete(workerId);
101102
this.handoff(worker);
102103
}

lib/internal/console/constructor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ const consoleMethods = {
519519
length++;
520520
}
521521
} else {
522-
for (const [k, v] of tabularData) {
522+
for (const { 0: k, 1: v } of tabularData) {
523523
ArrayPrototypePush(keys, _inspect(k));
524524
ArrayPrototypePush(values, _inspect(v));
525525
length++;

lib/internal/crypto/keys.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ for (const m of [[kKeyEncodingPKCS1, 'pkcs1'], [kKeyEncodingPKCS8, 'pkcs8'],
4848
// which requires the KeyObject base class to be implemented in C++.
4949
// The creation requires a callback to make sure that the NativeKeyObject
5050
// base class cannot exist without the other KeyObject implementations.
51-
const [
52-
KeyObject,
53-
SecretKeyObject,
54-
PublicKeyObject,
55-
PrivateKeyObject
56-
] = createNativeKeyObjectClass((NativeKeyObject) => {
51+
const {
52+
0: KeyObject,
53+
1: SecretKeyObject,
54+
2: PublicKeyObject,
55+
3: PrivateKeyObject,
56+
} = createNativeKeyObjectClass((NativeKeyObject) => {
5757
// Publicly visible KeyObject class.
5858
class KeyObject extends NativeKeyObject {
5959
constructor(type, handle) {

lib/internal/errors.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ function uvErrmapGet(name) {
421421
* @returns {Error}
422422
*/
423423
function uvException(ctx) {
424-
const [ code, uvmsg ] = uvErrmapGet(ctx.errno) || uvUnmappedError;
424+
const { 0: code, 1: uvmsg } = uvErrmapGet(ctx.errno) || uvUnmappedError;
425425
let message = `${code}: ${ctx.message || uvmsg}, ${ctx.syscall}`;
426426

427427
let path;
@@ -476,7 +476,7 @@ function uvException(ctx) {
476476
* @returns {Error}
477477
*/
478478
function uvExceptionWithHostPort(err, syscall, address, port) {
479-
const [ code, uvmsg ] = uvErrmapGet(err) || uvUnmappedError;
479+
const { 0: code, 1: uvmsg } = uvErrmapGet(err) || uvUnmappedError;
480480
const message = `${syscall} ${code}: ${uvmsg}`;
481481
let details = '';
482482

@@ -1235,7 +1235,8 @@ E('ERR_MANIFEST_ASSERT_INTEGRITY',
12351235
}" does not match the expected integrity.`;
12361236
if (realIntegrities.size) {
12371237
const sri = ArrayPrototypeJoin(
1238-
ArrayFrom(realIntegrities.entries(), ([alg, dgs]) => `${alg}-${dgs}`),
1238+
ArrayFrom(realIntegrities.entries(),
1239+
({ 0: alg, 1: dgs }) => `${alg}-${dgs}`),
12391240
' '
12401241
);
12411242
msg += ` Integrities found are: ${sri}`;

lib/internal/main/print_help.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,17 @@ function format(
110110
let text = '';
111111
let maxFirstColumnUsed = 0;
112112

113-
for (const [
114-
name, { helpText, type, value }
115-
] of ArrayPrototypeSort([...options.entries()])) {
113+
for (const {
114+
0: name, 1: { helpText, type, value }
115+
} of ArrayPrototypeSort([...options.entries()])) {
116116
if (!helpText) continue;
117117

118118
let displayName = name;
119119
const argDescription = getArgDescription(type);
120120
if (argDescription)
121121
displayName += `=${argDescription}`;
122122

123-
for (const [ from, to ] of aliases) {
123+
for (const { 0: from, 1: to } of aliases) {
124124
// For cases like e.g. `-e, --eval`.
125125
if (to[0] === name && to.length === 1) {
126126
displayName = `${from}, ${displayName}`;

lib/internal/modules/cjs/loader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function Module(id = '', parent) {
172172
}
173173

174174
const builtinModules = [];
175-
for (const [id, mod] of NativeModule.map) {
175+
for (const { 0: id, 1: mod } of NativeModule.map) {
176176
if (mod.canBeRequiredByUsers) {
177177
ArrayPrototypePush(builtinModules, id);
178178
}

lib/internal/policy/manifest.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ class Manifest {
350350
};
351351

352352
for (let i = 0; i < jsonResourcesEntries.length; i++) {
353-
const [originalHREF, resourceDescriptor] = jsonResourcesEntries[i];
353+
const { 0: originalHREF, 1: resourceDescriptor } =
354+
jsonResourcesEntries[i];
354355
const cascade = resourceDescriptor.cascade;
355356
const dependencyMap = resourceDescriptor.dependencies;
356357
const resourceHREF = resolve(originalHREF);
@@ -380,7 +381,7 @@ class Manifest {
380381

381382
const scopeIntegrities = this.#scopeIntegrities;
382383
for (let i = 0; i < jsonScopesEntries.length; i++) {
383-
const [originalHREF, scopeDescriptor] = jsonScopesEntries[i];
384+
const { 0: originalHREF, 1: scopeDescriptor } = jsonScopesEntries[i];
384385
const integrity = scopeDescriptor.integrity;
385386
const cascade = scopeDescriptor.cascade;
386387
const dependencyMap = scopeDescriptor.dependencies;

lib/internal/util/comparisons.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ function mapHasEqualEntry(set, map, key1, item1, strict, memo) {
518518
function mapEquiv(a, b, strict, memo) {
519519
let set = null;
520520

521-
for (const [key, item1] of a) {
521+
for (const { 0: key, 1: item1 } of a) {
522522
if (typeof key === 'object' && key !== null) {
523523
if (set === null) {
524524
set = new Set();
@@ -545,7 +545,7 @@ function mapEquiv(a, b, strict, memo) {
545545
}
546546

547547
if (set !== null) {
548-
for (const [key, item] of b) {
548+
for (const { 0: key, 1: item } of b) {
549549
if (typeof key === 'object' && key !== null) {
550550
if (!mapHasEqualEntry(set, a, key, item, strict, memo))
551551
return false;

lib/internal/util/inspect.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ function formatSet(value, ctx, ignored, recurseTimes) {
15361536
function formatMap(value, ctx, ignored, recurseTimes) {
15371537
const output = [];
15381538
ctx.indentationLvl += 2;
1539-
for (const [k, v] of value) {
1539+
for (const { 0: k, 1: v } of value) {
15401540
output.push(`${formatValue(ctx, k, recurseTimes)} => ` +
15411541
formatValue(ctx, v, recurseTimes));
15421542
}
@@ -1619,7 +1619,7 @@ function formatWeakMap(ctx, value, recurseTimes) {
16191619
}
16201620

16211621
function formatIterator(braces, ctx, value, recurseTimes) {
1622-
const [entries, isKeyValue] = previewEntries(value, true);
1622+
const { 0: entries, 1: isKeyValue } = previewEntries(value, true);
16231623
if (isKeyValue) {
16241624
// Mark entry iterators as such.
16251625
braces[0] = braces[0].replace(/ Iterator] {$/, ' Entries] {');
@@ -1631,7 +1631,7 @@ function formatIterator(braces, ctx, value, recurseTimes) {
16311631

16321632
function formatPromise(ctx, value, recurseTimes) {
16331633
let output;
1634-
const [state, result] = getPromiseDetails(value);
1634+
const { 0: state, 1: result } = getPromiseDetails(value);
16351635
if (state === kPending) {
16361636
output = [ctx.stylize('<pending>', 'special')];
16371637
} else {

lib/internal/worker/js_transferable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function setup() {
1919
// from .postMessage() calls. The format of `deserializeInfo` is generally
2020
// 'module:Constructor', e.g. 'internal/fs/promises:FileHandle'.
2121
setDeserializerCreateObjectFunction((deserializeInfo) => {
22-
const [ module, ctor ] = StringPrototypeSplit(deserializeInfo, ':');
22+
const { 0: module, 1: ctor } = StringPrototypeSplit(deserializeInfo, ':');
2323
const Ctor = require(module)[ctor];
2424
if (typeof Ctor !== 'function' ||
2525
!(Ctor.prototype instanceof JSTransferable)) {

lib/os.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ function getCheckedFunction(fn) {
7171
});
7272
}
7373

74-
const [
75-
type,
76-
version,
77-
release
78-
] = _getOSInformation();
74+
const {
75+
0: type,
76+
1: version,
77+
2: release,
78+
} = _getOSInformation();
7979

8080
const getHomeDirectory = getCheckedFunction(_getHomeDirectory);
8181
const getHostname = getCheckedFunction(_getHostname);

lib/repl.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,10 @@ function REPLServer(prompt,
381381
let entry;
382382
const tmpCompletionEnabled = self.isCompletionEnabled;
383383
while (entry = ArrayPrototypeShift(pausedBuffer)) {
384-
const [type, payload, isCompletionEnabled] = entry;
384+
const { 0: type, 1: payload, 2: isCompletionEnabled } = entry;
385385
switch (type) {
386386
case 'key': {
387-
const [d, key] = payload;
387+
const { 0: d, 1: key } = payload;
388388
self.isCompletionEnabled = isCompletionEnabled;
389389
self._ttyWrite(d, key);
390390
break;
@@ -1453,7 +1453,7 @@ function complete(line, callback) {
14531453
REPLServer.prototype.completeOnEditorMode = (callback) => (err, results) => {
14541454
if (err) return callback(err);
14551455

1456-
const [completions, completeOn = ''] = results;
1456+
const { 0: completions, 1: completeOn = '' } = results;
14571457
let result = ArrayPrototypeFilter(completions, Boolean);
14581458

14591459
if (completeOn && result.length !== 0) {

0 commit comments

Comments
 (0)