-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
lib: fix inspect deduplication logic #59687
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
base: main
Are you sure you want to change the base?
lib: fix inspect deduplication logic #59687
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #59687 +/- ##
==========================================
- Coverage 89.95% 88.29% -1.67%
==========================================
Files 667 702 +35
Lines 196813 206814 +10001
Branches 38425 39793 +1368
==========================================
+ Hits 177038 182599 +5561
- Misses 12200 16235 +4035
- Partials 7575 7980 +405
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with reverting the two cases / Highlighting the exact change where the change would be beneficial.
Co-authored-by: Ruben Bridgewater <[email protected]>
Co-authored-by: Ruben Bridgewater <[email protected]>
744630c
to
0a095ed
Compare
I won't block this change, but I think that "sometimes omitting the |
The intention when I added the |
I agree deduping is good - but I don't think strings should be divisible, and |
@ljharb it's a heuristic for the best behavior. We could guard against the case you mention, if you would like that (checking that the match is either at the end of the class name or that the next character is a capital letter). |
That makes the heuristic less likely to be wrong, but also more magical and implicit, which doesn't seem worth it to me. I defer to you. |
Co-authored-by: Ruben Bridgewater <[email protected]>
c14489f
to
47ddb0a
Compare
Failed to start CI⚠ Commits were pushed since the last approving review: ⚠ - lib: update inspect output format for subclasses ⚠ - test: add inspect tests for null constructor scenarios ⚠ - test: update syntax error assertion in ESM loader test ⚠ - lib: revert tag exclusion for getClassBase ⚠ - lib: revert tag exclusion for getFunctionBase ⚠ - test: rename subclasses for Map and Promise in inspect tests ⚠ - lib: Update lib/internal/util/inspect.js ⚠ - test: enhance util.inspect assertions ✘ Refusing to run CI on potentially unsafe PRhttps://github.com/nodejs/node/actions/runs/17830830316 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am struggling understanding the test cases.
I believe we need a few scenarios:
- class SetAbc extends Set {}
- class AbcMap extends Map {}
- class MiddleErrorPart extends Error {}
- class Settings extends Set {}
These cases should cover all possible scenarios and the outcome would be:
1., 2., and 3. are all not having the fallback.
4. Shows the Set next to the constructor name.
Null prototypes work differently, since we can not reconstruct the class fully and they are not impacted.
} else { | ||
const endPos = position + tag.length; | ||
if (endPos !== constructor.length && | ||
constructor[endPos + 1] === constructor[endPos + 1].toLowerCase()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had an off by one error writing this. It should be
constructor[endPos + 1] === constructor[endPos + 1].toLowerCase()) { | |
constructor[endPos] === constructor[endPos].toLowerCase()) { |
Fix deduplication logic for
inspect
output when dealing with constructor names that contain custom tags, but checking for tag followed by lowercase characters, e.g: avoiding unnecessary tagSet
from a constructor extended likeFooSet(3) { 1, 2, 3 }
from autil.inspect(new FooSet([1, 2, 3]))
but keeping it forSettings(3) [Set] { 1, 2, 3 }
from autil.inspect(new Settings([1, 2, 3]))
cc @BridgeAR