X Tutup
The Wayback Machine - https://web.archive.org/web/20210522082402/https://github.com/nodejs/node/pull/38697
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: refactor to use optional chaining #38697

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

@pd4d10
Copy link
Contributor

@pd4d10 pd4d10 commented May 16, 2021

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

Also see:
#38609

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
@aduh95
Copy link
Contributor

@aduh95 aduh95 commented May 16, 2021

I'm not sure we want to do that after #38245...
In any case this should be split into several PRs, it's less of a burden to review smaller PRs and we benchmark it more efficiently.

@@ -561,7 +561,7 @@ class Control extends EventEmitter {
}

get fd() {
return this.#channel ? this.#channel.fd : undefined;
return this.#channel?.fd ?? undefined;

This comment has been minimized.

@aduh95

aduh95 May 16, 2021
Contributor

Suggested change
return this.#channel?.fd ?? undefined;
return this.#channel?.fd;
@@ -221,7 +221,7 @@ const proxySocketHandler = {
if (stream.destroyed)
return false;
const request = stream[kRequest];
return request ? request.readable : stream.readable;
return request?.readable ?? stream.readable;

This comment has been minimized.

@aduh95

aduh95 May 16, 2021
Contributor

Suggested change
return request?.readable ?? stream.readable;
return stream[kRequest]?.readable ?? stream.readable;
@@ -199,7 +199,7 @@ function debugStream(id, sessionType, message, ...args) {

function debugStreamObj(stream, message, ...args) {
const session = stream[kSession];
const type = session ? session[kType] : undefined;
const type = session?.kType ?? undefined;

This comment has been minimized.

@aduh95

aduh95 May 16, 2021
Contributor

Suggested change
const type = session?.kType ?? undefined;
const type = stream[kSession]?.[kType];
@@ -709,7 +709,7 @@ OutgoingMessage.prototype.write = function write(chunk, encoding, callback) {
};

function onError(msg, err, callback) {
const triggerAsyncId = msg.socket ? msg.socket[async_id_symbol] : undefined;
const triggerAsyncId = msg.socket?.[async_id_symbol] ?? undefined;

This comment has been minimized.

@aduh95

aduh95 May 16, 2021
Contributor

Suggested change
const triggerAsyncId = msg.socket?.[async_id_symbol] ?? undefined;
const triggerAsyncId = msg.socket?.[async_id_symbol];
@pd4d10
Copy link
Contributor Author

@pd4d10 pd4d10 commented May 16, 2021

I'm not sure we want to do that after #38245...

OK. Given this information, I guess we should hold it until the performance issues solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
X Tutup