8000 Fix List.removeAfter() bug · immutable-js/immutable-js@d219218 · GitHub
[go: up one dir, main page]

Skip to content

Commit d219218

Browse files
author
Alexandre VICTOOR
committed
Fix List.removeAfter() bug
1 parent 81a9175 commit d219218

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

__tests__/List.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,11 @@ describe('List', () => {
722722
expect(o.get(0)).toBe('f');
723723
});
724724

725+
it('works with push and insert without phantom values', () => {
726+
const v = List.of().set(287, 287).push(42).insert(33, 33);
727+
expect(v.toJS().filter(item => item === 287)).toHaveLength(1);
728+
});
729+
725730
// TODO: assert that findIndex only calls the function as much as it needs to.
726731

727732
it('forEach iterates in the correct order', () => {

src/List.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,10 @@ class VNode {
304304
}
305305

306306
removeAfter(ownerID, level, index) {
307-
if (index === (level ? 1 << level : 0) || this.array.length === 0) {
307+
if (
308+
index === (level ? 1 << (level + 1) : SIZE) - 1 ||
309+
this.array.length === 0
310+
) {
308311
return this;
309312
}
310313
const sizeIndex = ((index - 1) >>> level) & MASK;

0 commit comments

Comments
 (0)
0