lib: refactor to use optional chaining#38697
Conversation
This PR migrates expressions such as `a ? a.b : c` to `a?.b ?? c` Codemod script: https://github.com/pd4d10/nodejs-codemod/blob/main/src/optional-chaining.ts
|
I'm not sure we want to do that after #38245... |
|
|
||
| get fd() { | ||
| return this.#channel ? this.#channel.fd : undefined; | ||
| return this.#channel?.fd ?? undefined; |
There was a problem hiding this comment.
| return this.#channel?.fd ?? undefined; | |
| return this.#channel?.fd; |
| return false; | ||
| const request = stream[kRequest]; | ||
| return request ? request.readable : stream.readable; | ||
| return request?.readable ?? stream.readable; |
There was a problem hiding this comment.
| return request?.readable ?? stream.readable; | |
| return stream[kRequest]?.readable ?? stream.readable; |
| function debugStreamObj(stream, message, ...args) { | ||
| const session = stream[kSession]; | ||
| const type = session ? session[kType] : undefined; | ||
| const type = session?.kType ?? undefined; |
There was a problem hiding this comment.
| const type = session?.kType ?? undefined; | |
| const type = stream[kSession]?.[kType]; |
|
|
||
| function onError(msg, err, callback) { | ||
| const triggerAsyncId = msg.socket ? msg.socket[async_id_symbol] : undefined; | ||
| const triggerAsyncId = msg.socket?.[async_id_symbol] ?? undefined; |
There was a problem hiding this comment.
| const triggerAsyncId = msg.socket?.[async_id_symbol] ?? undefined; | |
| const triggerAsyncId = msg.socket?.[async_id_symbol]; |
OK. Given this information, I guess we should hold it until the performance issues solved. |
Mifrill
left a comment
There was a problem hiding this comment.
Those changes look great, and I see the potential performance issue was also taken into consideration, that's awesome, however would like to raise a hand and ask if the chaining is slower than the ternary operator.
📝 CC @ronag #50337 (comment)
|
This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open. |
|
Closing this because it has stalled. Feel free to reopen if this issue/PR is still relevant, or to ping the collaborator who labelled it stalled if you have any questions. |
This PR migrates expressions such as
a ? a.b : ctoa?.b ?? cCodemod script:
https://github.com/pd4d10/nodejs-codemod/blob/main/src/optional-chaining.ts
Also see:
#38609