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

File tree

18 files changed

+45
-40
lines changed

18 files changed

+45
-40
lines changed

lib/_http_server.js

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

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

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

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

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

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

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
@@ -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

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

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

0 commit comments

Comments
 (0)