| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cbfc980 commit d803355
52 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -313,6 +313,7 @@ export default [ | |||
| 313 | 313 | 'node-core/no-unescaped-regexp-dot': 'error', | |
| 314 | 314 | 'node-core/no-duplicate-requires': 'error', | |
| 315 | 315 | 'node-core/prefer-proto': 'error', | |
| 316 | + 'node-core/prefer-optional-chaining': 'error', | ||
| 316 | 317 | }, | |
| 317 | 318 | }, | |
| 318 | 319 | // #endregion | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -128,7 +128,7 @@ function Agent(options) { | |||
| 128 | 128 | } | |
| 129 | 129 | ||
| 130 | 130 | const requests = this.requests[name]; | |
| 131 | - if (requests && requests.length) { | ||
| 131 | + if (requests?.length) { | ||
| 132 | 132 | const req = requests.shift(); | |
| 133 | 133 | const reqAsyncRes = req[kRequestAsyncResource]; | |
| 134 | 134 | if (reqAsyncRes) { | |
@@ -437,7 +437,7 @@ Agent.prototype.removeSocket = function removeSocket(s, options) { | |||
| 437 | 437 | } | |
| 438 | 438 | ||
| 439 | 439 | let req; | |
| 440 | - if (this.requests[name] && this.requests[name].length) { | ||
| 440 | + if (this.requests[name]?.length) { | ||
| 441 | 441 | debug('removeSocket, have a request, make a socket'); | |
| 442 | 442 | req = this.requests[name][0]; | |
| 443 | 443 | } else { | |
@@ -449,7 +449,7 @@ Agent.prototype.removeSocket = function removeSocket(s, options) { | |||
| 449 | 449 | for (let i = 0; i < keys.length; i++) { | |
| 450 | 450 | const prop = keys[i]; | |
| 451 | 451 | // Check whether this specific origin is already at maxSockets | |
| 452 | - if (this.sockets[prop] && this.sockets[prop].length) break; | ||
| 452 | + if (this.sockets[prop]?.length) break; | ||
| 453 | 453 | debug('removeSocket, have a request with different origin,' + | |
| 454 | 454 | ' make a socket'); | |
| 455 | 455 | req = this.requests[prop][0]; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -174,7 +174,7 @@ function ClientRequest(input, options, cb) { | |||
| 174 | 174 | ||
| 175 | 175 | const protocol = options.protocol || defaultAgent.protocol; | |
| 176 | 176 | let expectedProtocol = defaultAgent.protocol; | |
| 177 | - if (this.agent && this.agent.protocol) | ||
| 177 | + if (this.agent?.protocol) | ||
| 178 | 178 | expectedProtocol = this.agent.protocol; | |
| 179 | 179 | ||
| 180 | 180 | if (options.path) { | |
@@ -190,7 +190,7 @@ function ClientRequest(input, options, cb) { | |||
| 190 | 190 | } | |
| 191 | 191 | ||
| 192 | 192 | const defaultPort = options.defaultPort || | |
| 193 | - (this.agent && this.agent.defaultPort); | ||
| 193 | + (this.agent?.defaultPort); | ||
| 194 | 194 | ||
| 195 | 195 | const optsWithoutSignal = { __proto__: null, ...options }; | |
| 196 | 196 | ||
@@ -553,7 +553,7 @@ function socketOnData(d) { | |||
| 553 | 553 | socket.destroy(); | |
| 554 | 554 | req.socket._hadError = true; | |
| 555 | 555 | emitErrorEvent(req, ret); | |
| 556 | - } else if (parser.incoming && parser.incoming.upgrade) { | ||
| 556 | + } else if (parser.incoming?.upgrade) { | ||
| 557 | 557 | // Upgrade (if status code 101) or CONNECT | |
| 558 | 558 | const bytesParsed = ret; | |
| 559 | 559 | const res = parser.incoming; | |
@@ -591,7 +591,7 @@ function socketOnData(d) { | |||
| 591 | 591 | // Requested Upgrade or used CONNECT method, but have no handler. | |
| 592 | 592 | socket.destroy(); | |
| 593 | 593 | } | |
| 594 | - } else if (parser.incoming && parser.incoming.complete && | ||
| 594 | + } else if (parser.incoming?.complete && | ||
| 595 | 595 | // When the status code is informational (100, 102-199), | |
| 596 | 596 | // the server will send a final response after this client | |
| 597 | 597 | // sends a request body, so we must not free the parser. | |
@@ -838,7 +838,7 @@ function tickOnSocket(req, socket) { | |||
| 838 | 838 | ||
| 839 | 839 | if ( | |
| 840 | 840 | req.timeout !== undefined || | |
| 841 | - (req.agent && req.agent.options && req.agent.options.timeout) | ||
| 841 | + (req.agent?.options?.timeout) | ||
| 842 | 842 | ) { | |
| 843 | 843 | listenSocketTimeout(req); | |
| 844 | 844 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -85,8 +85,7 @@ function parserOnHeadersComplete(versionMajor, versionMinor, headers, method, | |||
| 85 | 85 | } | |
| 86 | 86 | ||
| 87 | 87 | // Parser is also used by http client | |
| 88 | - const ParserIncomingMessage = (socket && socket.server && | ||
| 89 | - socket.server[kIncomingMessage]) || | ||
| 88 | + const ParserIncomingMessage = (socket?.server?.[kIncomingMessage]) || | ||
| 90 | 89 | IncomingMessage; | |
| 91 | 90 | ||
| 92 | 91 | const incoming = parser.incoming = new ParserIncomingMessage(socket); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -242,7 +242,7 @@ IncomingMessage.prototype._destroy = function _destroy(err, cb) { | |||
| 242 | 242 | ||
| 243 | 243 | IncomingMessage.prototype._addHeaderLines = _addHeaderLines; | |
| 244 | 244 | function _addHeaderLines(headers, n) { | |
| 245 | - if (headers && headers.length) { | ||
| 245 | + if (headers?.length) { | ||
| 246 | 246 | let dest; | |
| 247 | 247 | if (this.complete) { | |
| 248 | 248 | this.rawTrailers = headers; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -423,7 +423,7 @@ OutgoingMessage.prototype._send = function _send(data, encoding, callback, byteL | |||
| 423 | 423 | OutgoingMessage.prototype._writeRaw = _writeRaw; | |
| 424 | 424 | function _writeRaw(data, encoding, callback, size) { | |
| 425 | 425 | const conn = this[kSocket]; | |
| 426 | - if (conn && conn.destroyed) { | ||
| 426 | + if (conn?.destroyed) { | ||
| 427 | 427 | // The socket was destroyed. If we're still trying to write to it, | |
| 428 | 428 | // then we haven't gotten the 'close' event yet. | |
| 429 | 429 | return false; | |
@@ -789,7 +789,7 @@ OutgoingMessage.prototype.getHeader = function getHeader(name) { | |||
| 789 | 789 | return; | |
| 790 | 790 | ||
| 791 | 791 | const entry = headers[name.toLowerCase()]; | |
| 792 | - return entry && entry[1]; | ||
| 792 | + return entry?.[1]; | ||
| 793 | 793 | }; | |
| 794 | 794 | ||
| 795 | 795 | ||
@@ -1073,7 +1073,7 @@ OutgoingMessage.prototype.addTrailers = function addTrailers(headers) { | |||
| 1073 | 1073 | }; | |
| 1074 | 1074 | ||
| 1075 | 1075 | function onFinish(outmsg) { | |
| 1076 | - if (outmsg && outmsg.socket && outmsg.socket._hadError) return; | ||
| 1076 | + if (outmsg?.socket?._hadError) return; | ||
| 1077 | 1077 | outmsg.emit('finish'); | |
| 1078 | 1078 | } | |
| 1079 | 1079 | ||
@@ -1188,7 +1188,7 @@ OutgoingMessage.prototype._finish = function _finish() { | |||
| 1188 | 1188 | OutgoingMessage.prototype._flush = function _flush() { | |
| 1189 | 1189 | const socket = this[kSocket]; | |
| 1190 | 1190 | ||
| 1191 | - if (socket && socket.writable) { | ||
| 1191 | + if (socket?.writable) { | ||
| 1192 | 1192 | // There might be remaining data in this.output; write it out | |
| 1193 | 1193 | const ret = this._flushOutput(socket); | |
| 1194 | 1194 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -738,7 +738,7 @@ function connectionListenerInternal(server, socket) { | |||
| 738 | 738 | socket.setEncoding = socketSetEncoding; | |
| 739 | 739 | ||
| 740 | 740 | // We only consume the socket if it has never been consumed before. | |
| 741 | - if (socket._handle && socket._handle.isStreamBase && | ||
| 741 | + if (socket._handle?.isStreamBase && | ||
| 742 | 742 | !socket._handle._consumed) { | |
| 743 | 743 | parser._consumed = true; | |
| 744 | 744 | socket._handle._consumed = true; | |
@@ -783,7 +783,7 @@ function socketOnDrain(socket, state) { | |||
| 783 | 783 | } | |
| 784 | 784 | ||
| 785 | 785 | function socketOnTimeout() { | |
| 786 | - const req = this.parser && this.parser.incoming; | ||
| 786 | + const req = this.parser?.incoming; | ||
| 787 | 787 | const reqTimeout = req && !req.complete && req.emit('timeout', this); | |
| 788 | 788 | const res = this._httpMessage; | |
| 789 | 789 | const resTimeout = res && res.emit('timeout', this); | |
@@ -918,7 +918,7 @@ function onParserExecuteCommon(server, socket, parser, state, ret, d) { | |||
| 918 | 918 | prepareError(ret, parser, d); | |
| 919 | 919 | debug('parse error', ret); | |
| 920 | 920 | socketOnError.call(socket, ret); | |
| 921 | - } else if (parser.incoming && parser.incoming.upgrade) { | ||
| 921 | + } else if (parser.incoming?.upgrade) { | ||
| 922 | 922 | // Upgrade or CONNECT | |
| 923 | 923 | const req = parser.incoming; | |
| 924 | 924 | debug('SERVER upgrade or connect', req.method); | |
@@ -963,7 +963,7 @@ function onParserExecuteCommon(server, socket, parser, state, ret, d) { | |||
| 963 | 963 | ||
| 964 | 964 | function clearIncoming(req) { | |
| 965 | 965 | req = req || this; | |
| 966 | - const parser = req.socket && req.socket.parser; | ||
| 966 | + const parser = req.socket?.parser; | ||
| 967 | 967 | // Reset the .incoming property so that the request object can be gc'ed. | |
| 968 | 968 | if (parser && parser.incoming === req) { | |
| 969 | 969 | if (req.readableEnded) { | |
@@ -1180,7 +1180,7 @@ function onSocketResume() { | |||
| 1180 | 1180 | } | |
| 1181 | 1181 | ||
| 1182 | 1182 | function onSocketPause() { | |
| 1183 | - if (this._handle && this._handle.reading) { | ||
| 1183 | + if (this._handle?.reading) { | ||
| 1184 | 1184 | this._handle.reading = false; | |
| 1185 | 1185 | this._handle.readStop(); | |
| 1186 | 1186 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -489,7 +489,7 @@ function initRead(tlsSocket, socket) { | |||
| 489 | 489 | return; | |
| 490 | 490 | ||
| 491 | 491 | // Socket already has some buffered data - emulate receiving it | |
| 492 | - if (socket && socket.readableLength) { | ||
| 492 | + if (socket?.readableLength) { | ||
| 493 | 493 | let buf; | |
| 494 | 494 | while ((buf = socket.read()) !== null) | |
| 495 | 495 | tlsSocket._handle.receive(buf); | |
@@ -1683,7 +1683,7 @@ function onConnectSecure() { | |||
| 1683 | 1683 | if (!verifyError && !this.isSessionReused()) { | |
| 1684 | 1684 | const hostname = options.servername || | |
| 1685 | 1685 | options.host || | |
| 1686 | - (options.socket && options.socket._host) || | ||
| 1686 | + (options.socket?._host) || | ||
| 1687 | 1687 | 'localhost'; | |
| 1688 | 1688 | const cert = this.getPeerCertificate(true); | |
| 1689 | 1689 | verifyError = options.checkServerIdentity(hostname, cert); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -446,7 +446,7 @@ function expectedException(actual, expected, message, fn) { | |||
| 446 | 446 | message = 'The error is expected to be an instance of ' + | |
| 447 | 447 | `"${expected.name}". Received `; | |
| 448 | 448 | if (isError(actual)) { | |
| 449 | - const name = (actual.constructor && actual.constructor.name) || | ||
| 449 | + const name = (actual.constructor?.name) || | ||
| 450 | 450 | actual.name; | |
| 451 | 451 | if (expected.name === name) { | |
| 452 | 452 | message += 'an error with identical name but a different prototype.'; | |
@@ -569,7 +569,7 @@ function expectsError(stackStartFn, actual, error, message) { | |||
| 569 | 569 | ||
| 570 | 570 | if (actual === NO_EXCEPTION_SENTINEL) { | |
| 571 | 571 | let details = ''; | |
| 572 | - if (error && error.name) { | ||
| 572 | + if (error?.name) { | ||
| 573 | 573 | details += ` (${error.name})`; | |
| 574 | 574 | } | |
| 575 | 575 | details += message ? `: ${message}` : '.'; | |
@@ -627,7 +627,7 @@ function expectsNoError(stackStartFn, actual, error, message) { | |||
| 627 | 627 | expected: error, | |
| 628 | 628 | operator: stackStartFn.name, | |
| 629 | 629 | message: `Got unwanted ${fnType}${details}\n` + | |
| 630 | - `Actual message: "${actual && actual.message}"`, | ||
| 630 | + `Actual message: "${actual?.message}"`, | ||
| 631 | 631 | stackStartFn, | |
| 632 | 632 | }); | |
| 633 | 633 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -392,17 +392,15 @@ function execFile(file, args, options, callback) { | |||
| 392 | 392 | let stderr; | |
| 393 | 393 | if (encoding || | |
| 394 | 394 | ( | |
| 395 | - child.stdout && | ||
| 396 | - child.stdout.readableEncoding | ||
| 395 | + child.stdout?.readableEncoding | ||
| 397 | 396 | )) { | |
| 398 | 397 | stdout = ArrayPrototypeJoin(_stdout, ''); | |
| 399 | 398 | } else { | |
| 400 | 399 | stdout = Buffer.concat(_stdout); | |
| 401 | 400 | } | |
| 402 | 401 | if (encoding || | |
| 403 | 402 | ( | |
| 404 | - child.stderr && | ||
| 405 | - child.stderr.readableEncoding | ||
| 403 | + child.stderr?.readableEncoding | ||
| 406 | 404 | )) { | |
| 407 | 405 | stderr = ArrayPrototypeJoin(_stderr, ''); | |
| 408 | 406 | } else { | |
@@ -855,7 +853,7 @@ function spawnSync(file, args, options) { | |||
| 855 | 853 | ||
| 856 | 854 | // We may want to pass data in on any given fd, ensure it is a valid buffer | |
| 857 | 855 | for (let i = 0; i < options.stdio.length; i++) { | |
| 858 | - const input = options.stdio[i] && options.stdio[i].input; | ||
| 856 | + const input = options.stdio[i]?.input; | ||
| 859 | 857 | if (input != null) { | |
| 860 | 858 | const pipe = options.stdio[i] = { ...options.stdio[i] }; | |
| 861 | 859 | if (isArrayBufferView(input)) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments