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: remove unnecessary optional chaining #55728

Merged
merged 3 commits into from
Nov 7, 2024

Conversation

gurgunday
Copy link
Contributor

From the V8 blog:

Still, be considerate about using more than one optional chaining operator in a single chain. If a value is guaranteed to not be nullish, then using ?. to access properties on it is discouraged.

It adds more bytecode to each property access, in all these cases we know that the variables are not nullish

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Nov 5, 2024
Copy link

codecov bot commented Nov 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.40%. Comparing base (58a7b00) to head (557ac67).
Report is 22 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #55728   +/-   ##
=======================================
  Coverage   88.40%   88.40%           
=======================================
  Files         654      654           
  Lines      187655   187747   +92     
  Branches    36111    36123   +12     
=======================================
+ Hits       165889   165984   +95     
- Misses      14996    15007   +11     
+ Partials     6770     6756   -14     
Files with missing lines Coverage Δ
lib/events.js 99.75% <100.00%> (ø)
lib/fs.js 98.14% <100.00%> (ø)
lib/internal/fs/promises.js 98.24% <100.00%> (ø)
lib/internal/fs/read/context.js 94.57% <100.00%> (ø)
lib/internal/fs/watchers.js 85.78% <100.00%> (ø)
lib/timers/promises.js 99.15% <100.00%> (ø)

... and 34 files with indirect coverage changes

@anonrig anonrig added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Nov 5, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 5, 2024
@nodejs-github-bot
Copy link
Collaborator

Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could have a lint rule for that, that'd be neat

@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 6, 2024
Copy link
Contributor

@LiviaMedeiros LiviaMedeiros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as is, but pointing out that there are still more unnecessary ?.s around.
Also perhaps there are implicitly redundant optional chainings in internal functions, but we have to ensure that every { signal: null } case is covered by tests before removing them.

lib/events.js Outdated Show resolved Hide resolved
lib/events.js Show resolved Hide resolved
Co-authored-by: Livia Medeiros <[email protected]>
@gurgunday
Copy link
Contributor Author

@LiviaMedeiros @aduh95 I applied the first suggestion :)

@nodejs-github-bot

This comment was marked as outdated.

@LiviaMedeiros LiviaMedeiros added the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Nov 6, 2024
lib/events.js Outdated Show resolved Hide resolved
Co-authored-by: Antoine du Hamel <[email protected]>
@nodejs-github-bot

This comment was marked as outdated.

@gurgunday
Copy link
Contributor Author

@aduh95 can you relaunch the failed ones?

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 7, 2024
@nodejs-github-bot nodejs-github-bot merged commit 7788999 into nodejs:main Nov 7, 2024
51 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 7788999

@gurgunday gurgunday deleted the abort branch November 9, 2024 11:30
aduh95 pushed a commit that referenced this pull request Nov 16, 2024
PR-URL: #55728
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
tpoisseau pushed a commit to tpoisseau/node that referenced this pull request Nov 21, 2024
PR-URL: nodejs#55728
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Ceres6 pushed a commit to Ceres6/node that referenced this pull request Nov 26, 2024
PR-URL: nodejs#55728
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
ruyadorno pushed a commit that referenced this pull request Nov 27, 2024
PR-URL: #55728
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
ruyadorno pushed a commit that referenced this pull request Nov 27, 2024
PR-URL: #55728
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
ruyadorno pushed a commit that referenced this pull request Nov 27, 2024
PR-URL: #55728
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants