Skip to content

Commit

Permalink
lib: remove use of array destructuring
Browse files Browse the repository at this point in the history
PR-URL: #36818
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
aduh95 authored and danielleadams committed Mar 16, 2021
1 parent 236ba04 commit daa4ac5
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 40 deletions.
2 changes: 1 addition & 1 deletion lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ Server.prototype.setTimeout = function setTimeout(msecs, callback) {
Server.prototype[EE.captureRejectionSymbol] = function(err, event, ...args) {
switch (event) {
case 'request':
const [ , res] = args;
const { 1: res } = args;
if (!res.headersSent && !res.writableEnded) {
// Don't leak headers.
ArrayPrototypeForEach(res.getHeaderNames(),
Expand Down
4 changes: 2 additions & 2 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,15 @@ function getErrMessage(message, fn) {
}
fd = openSync(filename, 'r', 0o666);
// Reset column and message.
[column, message] = getCode(fd, line, column);
({ 0: column, 1: message } = getCode(fd, line, column));
// Flush unfinished multi byte characters.
decoder.end();
} else {
for (let i = 0; i < line; i++) {
code = StringPrototypeSlice(code,
StringPrototypeIndexOf(code, '\n') + 1);
}
[column, message] = parseCode(code, column);
({ 0: column, 1: message } = parseCode(code, column));
}
// Always normalize indentation, otherwise the message could look weird.
if (StringPrototypeIncludes(message, '\n')) {
Expand Down
2 changes: 1 addition & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function enhanceStackTrace(err, own) {
const errStack = err.stack.split('\n').slice(1);
const ownStack = own.stack.split('\n').slice(1);

const [ len, off ] = identicalSequenceRange(ownStack, errStack);
const { 0: len, 1: off } = identicalSequenceRange(ownStack, errStack);
if (len > 0) {
ownStack.splice(off + 1, len - 2,
' [... lines matching original stack trace ...]');
Expand Down
3 changes: 2 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2073,7 +2073,8 @@ function copyFileSync(src, dest, mode) {
function lazyLoadStreams() {
if (!ReadStream) {
({ ReadStream, WriteStream } = require('internal/fs/streams'));
[ FileReadStream, FileWriteStream ] = [ ReadStream, WriteStream ];
FileReadStream = ReadStream;
FileWriteStream = WriteStream;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/internal/bootstrap/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class NativeModule {
// To be called during pre-execution when --expose-internals is on.
// Enables the user-land module loader to access internal modules.
static exposeInternals() {
for (const [id, mod] of NativeModule.map) {
for (const { 0: id, 1: mod } of NativeModule.map) {
// Do not expose this to user land even with --expose-internals.
if (id !== loaderId) {
mod.canBeRequiredByUsers = true;
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/cluster/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const cluster = new EventEmitter();
const intercom = new EventEmitter();
const SCHED_NONE = 1;
const SCHED_RR = 2;
const [ minPort, maxPort ] = [ 1024, 65535 ];
const minPort = 1024;
const maxPort = 65535;
const { validatePort } = require('internal/validators');

module.exports = cluster;
Expand Down
5 changes: 3 additions & 2 deletions lib/internal/cluster/round_robin_handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ RoundRobinHandle.prototype.remove = function(worker) {

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

if (ArrayIsArray(workerEntry)) {
const [ workerId, worker ] = workerEntry;
const { 0: workerId, 1: worker } = workerEntry;
this.free.delete(workerId);
this.handoff(worker);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ const consoleMethods = {
length++;
}
} else {
for (const [k, v] of tabularData) {
for (const { 0: k, 1: v } of tabularData) {
ArrayPrototypePush(keys, _inspect(k));
ArrayPrototypePush(values, _inspect(v));
length++;
Expand Down
12 changes: 6 additions & 6 deletions lib/internal/crypto/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ for (const m of [[kKeyEncodingPKCS1, 'pkcs1'], [kKeyEncodingPKCS8, 'pkcs8'],
// which requires the KeyObject base class to be implemented in C++.
// The creation requires a callback to make sure that the NativeKeyObject
// base class cannot exist without the other KeyObject implementations.
const [
KeyObject,
SecretKeyObject,
PublicKeyObject,
PrivateKeyObject,
] = createNativeKeyObjectClass((NativeKeyObject) => {
const {
0: KeyObject,
1: SecretKeyObject,
2: PublicKeyObject,
3: PrivateKeyObject,
} = createNativeKeyObjectClass((NativeKeyObject) => {
// Publicly visible KeyObject class.
class KeyObject extends NativeKeyObject {
constructor(type, handle) {
Expand Down
7 changes: 4 additions & 3 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ const captureLargerStackTrace = hideStackFrames(
* @returns {Error}
*/
const uvException = hideStackFrames(function uvException(ctx) {
const [code, uvmsg] = uvErrmapGet(ctx.errno) || uvUnmappedError;
const { 0: code, 1: uvmsg } = uvErrmapGet(ctx.errno) || uvUnmappedError;
let message = `${code}: ${ctx.message || uvmsg}, ${ctx.syscall}`;

let path;
Expand Down Expand Up @@ -485,7 +485,7 @@ const uvException = hideStackFrames(function uvException(ctx) {
*/
const uvExceptionWithHostPort = hideStackFrames(
function uvExceptionWithHostPort(err, syscall, address, port) {
const [code, uvmsg] = uvErrmapGet(err) || uvUnmappedError;
const { 0: code, 1: uvmsg } = uvErrmapGet(err) || uvUnmappedError;
const message = `${syscall} ${code}: ${uvmsg}`;
let details = '';

Expand Down Expand Up @@ -1243,7 +1243,8 @@ E('ERR_MANIFEST_ASSERT_INTEGRITY',
}" does not match the expected integrity.`;
if (realIntegrities.size) {
const sri = ArrayPrototypeJoin(
ArrayFrom(realIntegrities.entries(), ([alg, dgs]) => `${alg}-${dgs}`),
ArrayFrom(realIntegrities.entries(),
({ 0: alg, 1: dgs }) => `${alg}-${dgs}`),
' '
);
msg += ` Integrities found are: ${sri}`;
Expand Down
8 changes: 4 additions & 4 deletions lib/internal/main/print_help.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,17 @@ function format(
let text = '';
let maxFirstColumnUsed = 0;

for (const [
name, { helpText, type, value },
] of ArrayPrototypeSort([...options.entries()])) {
for (const {
0: name, 1: { helpText, type, value }
} of ArrayPrototypeSort([...options.entries()])) {
if (!helpText) continue;

let displayName = name;
const argDescription = getArgDescription(type);
if (argDescription)
displayName += `=${argDescription}`;

for (const [ from, to ] of aliases) {
for (const { 0: from, 1: to } of aliases) {
// For cases like e.g. `-e, --eval`.
if (to[0] === name && to.length === 1) {
displayName = `${from}, ${displayName}`;
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function Module(id = '', parent) {
}

const builtinModules = [];
for (const [id, mod] of NativeModule.map) {
for (const { 0: id, 1: mod } of NativeModule.map) {
if (mod.canBeRequiredByUsers) {
ArrayPrototypePush(builtinModules, id);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/internal/policy/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ class Manifest {
};

for (let i = 0; i < jsonResourcesEntries.length; i++) {
const [originalHREF, resourceDescriptor] = jsonResourcesEntries[i];
const { 0: originalHREF, 1: resourceDescriptor } =
jsonResourcesEntries[i];
const cascade = resourceDescriptor.cascade;
const dependencyMap = resourceDescriptor.dependencies;
const resourceHREF = resolve(originalHREF);
Expand Down Expand Up @@ -380,7 +381,7 @@ class Manifest {

const scopeIntegrities = this.#scopeIntegrities;
for (let i = 0; i < jsonScopesEntries.length; i++) {
const [originalHREF, scopeDescriptor] = jsonScopesEntries[i];
const { 0: originalHREF, 1: scopeDescriptor } = jsonScopesEntries[i];
const integrity = scopeDescriptor.integrity;
const cascade = scopeDescriptor.cascade;
const dependencyMap = scopeDescriptor.dependencies;
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ function mapHasEqualEntry(set, map, key1, item1, strict, memo) {
function mapEquiv(a, b, strict, memo) {
let set = null;

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

if (set !== null) {
for (const [key, item] of b) {
for (const { 0: key, 1: item } of b) {
if (typeof key === 'object' && key !== null) {
if (!mapHasEqualEntry(set, a, key, item, strict, memo))
return false;
Expand Down
6 changes: 3 additions & 3 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,7 @@ function formatSet(value, ctx, ignored, recurseTimes) {
function formatMap(value, ctx, ignored, recurseTimes) {
const output = [];
ctx.indentationLvl += 2;
for (const [k, v] of value) {
for (const { 0: k, 1: v } of value) {
output.push(`${formatValue(ctx, k, recurseTimes)} => ` +
formatValue(ctx, v, recurseTimes));
}
Expand Down Expand Up @@ -1636,7 +1636,7 @@ function formatWeakMap(ctx, value, recurseTimes) {
}

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

function formatPromise(ctx, value, recurseTimes) {
let output;
const [state, result] = getPromiseDetails(value);
const { 0: state, 1: result } = getPromiseDetails(value);
if (state === kPending) {
output = [ctx.stylize('<pending>', 'special')];
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/worker/js_transferable.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function setup() {
// from .postMessage() calls. The format of `deserializeInfo` is generally
// 'module:Constructor', e.g. 'internal/fs/promises:FileHandle'.
setDeserializerCreateObjectFunction((deserializeInfo) => {
const [ module, ctor ] = StringPrototypeSplit(deserializeInfo, ':');
const { 0: module, 1: ctor } = StringPrototypeSplit(deserializeInfo, ':');
const Ctor = require(module)[ctor];
if (typeof Ctor !== 'function' ||
!(Ctor.prototype instanceof JSTransferable)) {
Expand Down
10 changes: 5 additions & 5 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ function getCheckedFunction(fn) {
});
}

const [
type,
version,
release,
] = _getOSInformation();
const {
0: type,
1: version,
2: release,
} = _getOSInformation();

const getHomeDirectory = getCheckedFunction(_getHomeDirectory);
const getHostname = getCheckedFunction(_getHostname);
Expand Down
6 changes: 3 additions & 3 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,10 @@ function REPLServer(prompt,
let entry;
const tmpCompletionEnabled = self.isCompletionEnabled;
while (entry = ArrayPrototypeShift(pausedBuffer)) {
const [type, payload, isCompletionEnabled] = entry;
const { 0: type, 1: payload, 2: isCompletionEnabled } = entry;
switch (type) {
case 'key': {
const [d, key] = payload;
const { 0: d, 1: key } = payload;
self.isCompletionEnabled = isCompletionEnabled;
self._ttyWrite(d, key);
break;
Expand Down Expand Up @@ -1500,7 +1500,7 @@ function complete(line, callback) {
REPLServer.prototype.completeOnEditorMode = (callback) => (err, results) => {
if (err) return callback(err);

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

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

0 comments on commit daa4ac5

Please sign in to comment.