Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/SymbolTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ class SymbolTree {
removeNode.parent = null;
removeNode.previousSibling = null;
removeNode.nextSibling = null;
removeNode.cachedIndex = -1;
removeNode.cachedIndexVersion = NaN;

if (parentNode) {
parentNode.childrenChanged();
Expand Down
22 changes: 21 additions & 1 deletion test/SymbolTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,6 @@ test('children iterator reverse', (t) => {
t.end();
});


test('children iterator return value using a generator', (t) => {
const tree = new SymbolTree();
const a = o();
Expand Down Expand Up @@ -1119,6 +1118,27 @@ test('cached index warmed up by childrenToArray', (t) => {
t.end();
});

test('cached index purge', (t) => {
const tree = new SymbolTree();
const a = o();
const aa = o();
const b = o();
const ba = o();
const bb = o();

tree.appendChild(a, aa);
tree.appendChild(b, ba);
tree.appendChild(b, bb);

t.equal(0, tree.index(ba));
tree.remove(ba);
t.equal(-1, tree.index(ba));
tree.appendChild(a, ba);
t.equal(1, tree.index(ba));

t.end();
});

test('children count', (t) => {
// no need to test the caching since we already tested for that in childrenCount
const tree = new SymbolTree();
Expand Down