Skip to content

Commit

Permalink
chore: use optional chaining (nodejs#2666)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored and crysmags committed Feb 27, 2024
1 parent 41e001a commit 88a3233
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })]

Expand Down
2 changes: 1 addition & 1 deletion lib/api/api-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/api/api-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class PipelineHandler extends AsyncResource {
read: () => {
const { body } = this

if (body && body.resume) {
if (body?.resume) {
body.resume()
}
},
Expand Down
2 changes: 1 addition & 1 deletion lib/api/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/api/api-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 }))
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/api/api-upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/balanced-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion lib/fetch/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down
2 changes: 1 addition & 1 deletion lib/handler/RetryHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/mock/mock-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/proxy-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
: []

Expand Down
2 changes: 1 addition & 1 deletion lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function onTimeout () {
}

function refreshTimeout () {
if (fastNowTimeout && fastNowTimeout.refresh) {
if (fastNowTimeout?.refresh) {
fastNowTimeout.refresh()
} else {
clearTimeout(fastNowTimeout)
Expand Down

0 comments on commit 88a3233

Please sign in to comment.