Skip to content

Commit 88a3233

Browse files
Uzlopakcrysmags
authored andcommitted
chore: use optional chaining (nodejs#2666)
1 parent 41e001a commit 88a3233

File tree

15 files changed

+17
-17
lines changed

15 files changed

+17
-17
lines changed

lib/agent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Agent extends DispatcherBase {
4242
connect = { ...connect }
4343
}
4444

45-
this[kInterceptors] = options.interceptors && options.interceptors.Agent && Array.isArray(options.interceptors.Agent)
45+
this[kInterceptors] = options.interceptors?.Agent && Array.isArray(options.interceptors.Agent)
4646
? options.interceptors.Agent
4747
: [createRedirectInterceptor({ maxRedirections })]
4848

lib/api/api-connect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function connect (opts, callback) {
9696
if (typeof callback !== 'function') {
9797
throw err
9898
}
99-
const opaque = opts && opts.opaque
99+
const opaque = opts?.opaque
100100
queueMicrotask(() => callback(err, { opaque }))
101101
}
102102
}

lib/api/api-pipeline.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class PipelineHandler extends AsyncResource {
100100
read: () => {
101101
const { body } = this
102102

103-
if (body && body.resume) {
103+
if (body?.resume) {
104104
body.resume()
105105
}
106106
},

lib/api/api-request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function request (opts, callback) {
171171
if (typeof callback !== 'function') {
172172
throw err
173173
}
174-
const opaque = opts && opts.opaque
174+
const opaque = opts?.opaque
175175
queueMicrotask(() => callback(err, { opaque }))
176176
}
177177
}

lib/api/api-stream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class StreamHandler extends AsyncResource {
148148

149149
const needDrain = res.writableNeedDrain !== undefined
150150
? res.writableNeedDrain
151-
: res._writableState && res._writableState.needDrain
151+
: res._writableState?.needDrain
152152

153153
return needDrain !== true
154154
}
@@ -212,7 +212,7 @@ function stream (opts, factory, callback) {
212212
if (typeof callback !== 'function') {
213213
throw err
214214
}
215-
const opaque = opts && opts.opaque
215+
const opaque = opts?.opaque
216216
queueMicrotask(() => callback(err, { opaque }))
217217
}
218218
}

lib/api/api-upgrade.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function upgrade (opts, callback) {
9797
if (typeof callback !== 'function') {
9898
throw err
9999
}
100-
const opaque = opts && opts.opaque
100+
const opaque = opts?.opaque
101101
queueMicrotask(() => callback(err, { opaque }))
102102
}
103103
}

lib/balanced-pool.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class BalancedPool extends PoolBase {
5353
throw new InvalidArgumentError('factory must be a function.')
5454
}
5555

56-
this[kInterceptors] = opts.interceptors && opts.interceptors.BalancedPool && Array.isArray(opts.interceptors.BalancedPool)
56+
this[kInterceptors] = opts.interceptors?.BalancedPool && Array.isArray(opts.interceptors.BalancedPool)
5757
? opts.interceptors.BalancedPool
5858
: []
5959
this[kFactory] = factory

lib/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class Client extends DispatcherBase {
250250
})
251251
}
252252

253-
this[kInterceptors] = interceptors && interceptors.Client && Array.isArray(interceptors.Client)
253+
this[kInterceptors] = interceptors?.Client && Array.isArray(interceptors.Client)
254254
? interceptors.Client
255255
: [createRedirectInterceptor({ maxRedirections })]
256256
this[kUrl] = util.parseOrigin(url)

lib/core/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function isDestroyed (stream) {
187187
}
188188

189189
function isReadableAborted (stream) {
190-
const state = stream && stream._readableState
190+
const state = stream?._readableState
191191
return isDestroyed(stream) && state && !state.endEmitted
192192
}
193193

lib/fetch/response.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class Response {
238238
webidl.brandCheck(this, Response)
239239

240240
// 1. If this is unusable, then throw a TypeError.
241-
if (this.bodyUsed || (this.body && this.body.locked)) {
241+
if (this.bodyUsed || this.body?.locked) {
242242
throw webidl.errors.exception({
243243
header: 'Response.clone',
244244
message: 'Body has already been consumed.'

0 commit comments

Comments
 (0)