Skip to content

Commit 1ce8107

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

File tree

17 files changed

+43
-39
lines changed

17 files changed

+43
-39
lines changed

lib/_http_server.js

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 4 additions & 4 deletions
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}`;

0 commit comments

Comments
 (0)