diff --git a/lib/agent.js b/lib/agent.js index 636e72c65b2..9a07708654a 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -42,7 +42,7 @@ class Agent extends DispatcherBase { connect = { ...connect } } - this[kInterceptors] = options.interceptors && options.interceptors.Agent && Array.isArray(options.interceptors.Agent) + this[kInterceptors] = options.interceptors?.Agent && Array.isArray(options.interceptors.Agent) ? options.interceptors.Agent : [createRedirectInterceptor({ maxRedirections })] diff --git a/lib/api/api-connect.js b/lib/api/api-connect.js index 9a144fb62ba..d19e67f69a2 100644 --- a/lib/api/api-connect.js +++ b/lib/api/api-connect.js @@ -96,7 +96,7 @@ function connect (opts, callback) { if (typeof callback !== 'function') { throw err } - const opaque = opts && opts.opaque + const opaque = opts?.opaque queueMicrotask(() => callback(err, { opaque })) } } diff --git a/lib/api/api-pipeline.js b/lib/api/api-pipeline.js index 7b48e952b12..f5112415bf7 100644 --- a/lib/api/api-pipeline.js +++ b/lib/api/api-pipeline.js @@ -100,7 +100,7 @@ class PipelineHandler extends AsyncResource { read: () => { const { body } = this - if (body && body.resume) { + if (body?.resume) { body.resume() } }, diff --git a/lib/api/api-request.js b/lib/api/api-request.js index 39aa4c32cce..285c76de241 100644 --- a/lib/api/api-request.js +++ b/lib/api/api-request.js @@ -171,7 +171,7 @@ function request (opts, callback) { if (typeof callback !== 'function') { throw err } - const opaque = opts && opts.opaque + const opaque = opts?.opaque queueMicrotask(() => callback(err, { opaque })) } } diff --git a/lib/api/api-stream.js b/lib/api/api-stream.js index 58c74188420..0998c9f2da1 100644 --- a/lib/api/api-stream.js +++ b/lib/api/api-stream.js @@ -148,7 +148,7 @@ class StreamHandler extends AsyncResource { const needDrain = res.writableNeedDrain !== undefined ? res.writableNeedDrain - : res._writableState && res._writableState.needDrain + : res._writableState?.needDrain return needDrain !== true } @@ -212,7 +212,7 @@ function stream (opts, factory, callback) { if (typeof callback !== 'function') { throw err } - const opaque = opts && opts.opaque + const opaque = opts?.opaque queueMicrotask(() => callback(err, { opaque })) } } diff --git a/lib/api/api-upgrade.js b/lib/api/api-upgrade.js index 52767a36e4a..bed946fdca9 100644 --- a/lib/api/api-upgrade.js +++ b/lib/api/api-upgrade.js @@ -97,7 +97,7 @@ function upgrade (opts, callback) { if (typeof callback !== 'function') { throw err } - const opaque = opts && opts.opaque + const opaque = opts?.opaque queueMicrotask(() => callback(err, { opaque })) } } diff --git a/lib/balanced-pool.js b/lib/balanced-pool.js index 10bc6a47baf..cf06fcacedc 100644 --- a/lib/balanced-pool.js +++ b/lib/balanced-pool.js @@ -53,7 +53,7 @@ class BalancedPool extends PoolBase { throw new InvalidArgumentError('factory must be a function.') } - this[kInterceptors] = opts.interceptors && opts.interceptors.BalancedPool && Array.isArray(opts.interceptors.BalancedPool) + this[kInterceptors] = opts.interceptors?.BalancedPool && Array.isArray(opts.interceptors.BalancedPool) ? opts.interceptors.BalancedPool : [] this[kFactory] = factory diff --git a/lib/client.js b/lib/client.js index 7eb2d196d1b..ff23b772909 100644 --- a/lib/client.js +++ b/lib/client.js @@ -250,7 +250,7 @@ class Client extends DispatcherBase { }) } - this[kInterceptors] = interceptors && interceptors.Client && Array.isArray(interceptors.Client) + this[kInterceptors] = interceptors?.Client && Array.isArray(interceptors.Client) ? interceptors.Client : [createRedirectInterceptor({ maxRedirections })] this[kUrl] = util.parseOrigin(url) diff --git a/lib/core/util.js b/lib/core/util.js index 6a692465893..55bf9f49822 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -187,7 +187,7 @@ function isDestroyed (stream) { } function isReadableAborted (stream) { - const state = stream && stream._readableState + const state = stream?._readableState return isDestroyed(stream) && state && !state.endEmitted } diff --git a/lib/fetch/response.js b/lib/fetch/response.js index 37ac53015e8..69aba18ba6e 100644 --- a/lib/fetch/response.js +++ b/lib/fetch/response.js @@ -238,7 +238,7 @@ class Response { webidl.brandCheck(this, Response) // 1. If this is unusable, then throw a TypeError. - if (this.bodyUsed || (this.body && this.body.locked)) { + if (this.bodyUsed || this.body?.locked) { throw webidl.errors.exception({ header: 'Response.clone', message: 'Body has already been consumed.' diff --git a/lib/handler/RetryHandler.js b/lib/handler/RetryHandler.js index 05d55792c1f..2a2f878c00f 100644 --- a/lib/handler/RetryHandler.js +++ b/lib/handler/RetryHandler.js @@ -148,7 +148,7 @@ class RetryHandler { return } - let retryAfterHeader = headers != null && headers['retry-after'] + let retryAfterHeader = headers?.['retry-after'] if (retryAfterHeader) { retryAfterHeader = Number(retryAfterHeader) retryAfterHeader = Number.isNaN(retryAfterHeader) diff --git a/lib/mock/mock-agent.js b/lib/mock/mock-agent.js index 4b29cd0112f..3d26a6a65ba 100644 --- a/lib/mock/mock-agent.js +++ b/lib/mock/mock-agent.js @@ -29,10 +29,10 @@ class MockAgent extends Dispatcher { this[kIsMockActive] = true // Instantiate Agent and encapsulate - if ((opts && opts.agent && typeof opts.agent.dispatch !== 'function')) { + if ((opts?.agent && typeof opts.agent.dispatch !== 'function')) { throw new InvalidArgumentError('Argument opts.agent must implement Agent') } - const agent = opts && opts.agent ? opts.agent : new Agent(opts) + const agent = opts?.agent ? opts.agent : new Agent(opts) this[kAgent] = agent this[kClients] = agent[kClients] diff --git a/lib/pool.js b/lib/pool.js index e3cd3399e6b..e238ac3d94b 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -63,7 +63,7 @@ class Pool extends PoolBase { }) } - this[kInterceptors] = options.interceptors && options.interceptors.Pool && Array.isArray(options.interceptors.Pool) + this[kInterceptors] = options.interceptors?.Pool && Array.isArray(options.interceptors.Pool) ? options.interceptors.Pool : [] this[kConnections] = connections || null diff --git a/lib/proxy-agent.js b/lib/proxy-agent.js index 54b078a7d62..382be2a5940 100644 --- a/lib/proxy-agent.js +++ b/lib/proxy-agent.js @@ -43,7 +43,7 @@ class ProxyAgent extends DispatcherBase { super(opts) this[kProxy] = buildProxyOptions(opts) this[kAgent] = new Agent(opts) - this[kInterceptors] = opts.interceptors && opts.interceptors.ProxyAgent && Array.isArray(opts.interceptors.ProxyAgent) + this[kInterceptors] = opts.interceptors?.ProxyAgent && Array.isArray(opts.interceptors.ProxyAgent) ? opts.interceptors.ProxyAgent : [] diff --git a/lib/timers.js b/lib/timers.js index 5782217a0e0..23a6d2b5223 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -39,7 +39,7 @@ function onTimeout () { } function refreshTimeout () { - if (fastNowTimeout && fastNowTimeout.refresh) { + if (fastNowTimeout?.refresh) { fastNowTimeout.refresh() } else { clearTimeout(fastNowTimeout)