Repository navigation
Fix LinkedMap.delete result for falsy values - #1943
Open
Raunak Kumar Pandey (raunakpandey1) wants to merge 1 commit into
Open
Raunak Kumar Pandey (raunakpandey1) wants to merge 1 commit into
Raunak Kumar Pandey (raunakpandey1) wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change making LinkedMap and LRUCache deletion results reflect key presence.
No open issues 🎉
What changed in this PR
Fixes #1942 by making LinkedMap.delete return whether the key existed, regardless of its stored value. The correction also applies to LRUCache, which inherits the method.
Changes:
- Check key presence before using the existing removal path.
- Add regression tests for both classes covering falsy and truthy values, missing and repeated deletions, size, and iteration order.
| File | Description |
|---|---|
jsonrpc/src/common/test/linkedMap.test.ts |
Adds deletion regression coverage for LinkedMap and LRUCache. |
jsonrpc/src/common/linkedMap.ts |
Returns key presence instead of the removed value’s truthiness. |
Review effort: Balanced
Author
|
@microsoft-github-policy-service agree
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LinkedMap.deleteremoves entries with falsy stored values but returnsfalse, because it converts the value returned byremoveto a boolean. This also affects the exportedLRUCache, which inherits the method.Check key presence before calling the existing removal path so deletion reports whether the key existed. The regression tests exercise both classes with
0,-0,false,'',null,undefined,NaN, and a truthy control. They also check absent/repeated deletions, size, and iteration order.Fixes #1942.
Validation on macOS arm64, Node.js 22.22.3:
false !== truefor value0).npm run compile:jsonrpcpassed.npm --prefix jsonrpc run test:node: 79 passing. The transport tests required local socket permissions.npm --prefix jsonrpc run lintpassed, with an existing stylistic configuration deprecation warning.git diff --checkpassed.