Skip to content

Commit daa4ac5

Browse files
aduh95danielleadams
authored andcommitted
lib: remove use of array destructuring
PR-URL: #36818 Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 236ba04 commit daa4ac5

18 files changed

+45
-40
lines changed

lib/_http_server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ Server.prototype.setTimeout = function setTimeout(msecs, callback) {
415415
Server.prototype[EE.captureRejectionSymbol] = function(err, event, ...args) {
416416
switch (event) {
417417
case 'request':
418-
const [ , res] = args;
418+
const { 1: res } = args;
419419
if (!res.headersSent && !res.writableEnded) {
420420
// Don't leak headers.
421421
ArrayPrototypeForEach(res.getHeaderNames(),

lib/assert.js

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

lib/events.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function enhanceStackTrace(err, own) {
315315
const errStack = err.stack.split('\n').slice(1);
316316
const ownStack = own.stack.split('\n').slice(1);
317317

318-
const [ len, off ] = identicalSequenceRange(ownStack, errStack);
318+
const { 0: len, 1: off } = identicalSequenceRange(ownStack, errStack);
319319
if (len > 0) {
320320
ownStack.splice(off + 1, len - 2,
321321
' [... lines matching original stack trace ...]');

lib/fs.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2073,7 +2073,8 @@ function copyFileSync(src, dest, mode) {
20732073
function lazyLoadStreams() {
20742074
if (!ReadStream) {
20752075
({ ReadStream, WriteStream } = require('internal/fs/streams'));
2076-
[ FileReadStream, FileWriteStream ] = [ ReadStream, WriteStream ];
2076+
FileReadStream = ReadStream;
2077+
FileWriteStream = WriteStream;
20772078
}
20782079
}
20792080

lib/internal/bootstrap/loaders.js

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

lib/internal/cluster/master.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const cluster = new EventEmitter();
2323
const intercom = new EventEmitter();
2424
const SCHED_NONE = 1;
2525
const SCHED_RR = 2;
26-
const [ minPort, maxPort ] = [ 1024, 65535 ];
26+
const minPort = 1024;
27+
const maxPort = 65535;
2728
const { validatePort } = require('internal/validators');
2829

2930
module.exports = cluster;

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
@@ -525,7 +525,7 @@ const consoleMethods = {
525525
length++;
526526
}
527527
} else {
528-
for (const [k, v] of tabularData) {
528+
for (const { 0: k, 1: v } of tabularData) {
529529
ArrayPrototypePush(keys, _inspect(k));
530530
ArrayPrototypePush(values, _inspect(v));
531531
length++;

lib/internal/crypto/keys.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ for (const m of [[kKeyEncodingPKCS1, 'pkcs1'], [kKeyEncodingPKCS8, 'pkcs8'],
8686
// which requires the KeyObject base class to be implemented in C++.
8787
// The creation requires a callback to make sure that the NativeKeyObject
8888
// base class cannot exist without the other KeyObject implementations.
89-
const [
90-
KeyObject,
91-
SecretKeyObject,
92-
PublicKeyObject,
93-
PrivateKeyObject,
94-
] = createNativeKeyObjectClass((NativeKeyObject) => {
89+
const {
90+
0: KeyObject,
91+
1: SecretKeyObject,
92+
2: PublicKeyObject,
93+
3: PrivateKeyObject,
94+
} = createNativeKeyObjectClass((NativeKeyObject) => {
9595
// Publicly visible KeyObject class.
9696
class KeyObject extends NativeKeyObject {
9797
constructor(type, handle) {

lib/internal/errors.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ const captureLargerStackTrace = hideStackFrames(
429429
* @returns {Error}
430430
*/
431431
const uvException = hideStackFrames(function uvException(ctx) {
432-
const [code, uvmsg] = uvErrmapGet(ctx.errno) || uvUnmappedError;
432+
const { 0: code, 1: uvmsg } = uvErrmapGet(ctx.errno) || uvUnmappedError;
433433
let message = `${code}: ${ctx.message || uvmsg}, ${ctx.syscall}`;
434434

435435
let path;
@@ -485,7 +485,7 @@ const uvException = hideStackFrames(function uvException(ctx) {
485485
*/
486486
const uvExceptionWithHostPort = hideStackFrames(
487487
function uvExceptionWithHostPort(err, syscall, address, port) {
488-
const [code, uvmsg] = uvErrmapGet(err) || uvUnmappedError;
488+
const { 0: code, 1: uvmsg } = uvErrmapGet(err) || uvUnmappedError;
489489
const message = `${syscall} ${code}: ${uvmsg}`;
490490
let details = '';
491491

@@ -1243,7 +1243,8 @@ E('ERR_MANIFEST_ASSERT_INTEGRITY',
12431243
}" does not match the expected integrity.`;
12441244
if (realIntegrities.size) {
12451245
const sri = ArrayPrototypeJoin(
1246-
ArrayFrom(realIntegrities.entries(), ([alg, dgs]) => `${alg}-${dgs}`),
1246+
ArrayFrom(realIntegrities.entries(),
1247+
({ 0: alg, 1: dgs }) => `${alg}-${dgs}`),
12471248
' '
12481249
);
12491250
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
@@ -485,7 +485,7 @@ function mapHasEqualEntry(set, map, key1, item1, strict, memo) {
485485
function mapEquiv(a, b, strict, memo) {
486486
let set = null;
487487

488-
for (const [key, item1] of a) {
488+
for (const { 0: key, 1: item1 } of a) {
489489
if (typeof key === 'object' && key !== null) {
490490
if (set === null) {
491491
set = new SafeSet();
@@ -512,7 +512,7 @@ function mapEquiv(a, b, strict, memo) {
512512
}
513513

514514
if (set !== null) {
515-
for (const [key, item] of b) {
515+
for (const { 0: key, 1: item } of b) {
516516
if (typeof key === 'object' && key !== null) {
517517
if (!mapHasEqualEntry(set, a, key, item, strict, memo))
518518
return false;

lib/internal/util/inspect.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ function formatSet(value, ctx, ignored, recurseTimes) {
15521552
function formatMap(value, ctx, ignored, recurseTimes) {
15531553
const output = [];
15541554
ctx.indentationLvl += 2;
1555-
for (const [k, v] of value) {
1555+
for (const { 0: k, 1: v } of value) {
15561556
output.push(`${formatValue(ctx, k, recurseTimes)} => ` +
15571557
formatValue(ctx, v, recurseTimes));
15581558
}
@@ -1636,7 +1636,7 @@ function formatWeakMap(ctx, value, recurseTimes) {
16361636
}
16371637

16381638
function formatIterator(braces, ctx, value, recurseTimes) {
1639-
const [entries, isKeyValue] = previewEntries(value, true);
1639+
const { 0: entries, 1: isKeyValue } = previewEntries(value, true);
16401640
if (isKeyValue) {
16411641
// Mark entry iterators as such.
16421642
braces[0] = braces[0].replace(/ Iterator] {$/, ' Entries] {');
@@ -1648,7 +1648,7 @@ function formatIterator(braces, ctx, value, recurseTimes) {
16481648

16491649
function formatPromise(ctx, value, recurseTimes) {
16501650
let output;
1651-
const [state, result] = getPromiseDetails(value);
1651+
const { 0: state, 1: result } = getPromiseDetails(value);
16521652
if (state === kPending) {
16531653
output = [ctx.stylize('<pending>', 'special')];
16541654
} 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
@@ -382,10 +382,10 @@ function REPLServer(prompt,
382382
let entry;
383383
const tmpCompletionEnabled = self.isCompletionEnabled;
384384
while (entry = ArrayPrototypeShift(pausedBuffer)) {
385-
const [type, payload, isCompletionEnabled] = entry;
385+
const { 0: type, 1: payload, 2: isCompletionEnabled } = entry;
386386
switch (type) {
387387
case 'key': {
388-
const [d, key] = payload;
388+
const { 0: d, 1: key } = payload;
389389
self.isCompletionEnabled = isCompletionEnabled;
390390
self._ttyWrite(d, key);
391391
break;
@@ -1500,7 +1500,7 @@ function complete(line, callback) {
15001500
REPLServer.prototype.completeOnEditorMode = (callback) => (err, results) => {
15011501
if (err) return callback(err);
15021502

1503-
const [completions, completeOn = ''] = results;
1503+
const { 0: completions, 1: completeOn = '' } = results;
15041504
let result = ArrayPrototypeFilter(completions, Boolean);
15051505

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

0 commit comments

Comments
 (0)