Skip to content

Commit 22b9d4b

Browse files
Fix bug that could corrupt the index cache
1 parent 77d615a commit 22b9d4b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/SymbolTree.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,13 @@ class SymbolTree {
265265
const filter = (options && options.filter ) || returnTrue;
266266
const thisArg = (options && options.thisArg) || undefined;
267267

268-
let object = this._node(parent).firstChild;
268+
const parentNode = this._node(parent);
269+
let object = parentNode.firstChild;
269270
let index = 0;
270271

271272
while (object) {
272273
const node = this._node(object);
273-
node.setCachedIndex(parent, index);
274+
node.setCachedIndex(parentNode, index);
274275

275276
if (filter.call(thisArg, object)) {
276277
array.push(object);

test/SymbolTree.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,11 @@ test('cached index warmed up by childrenToArray', function(t) {
10951095
t.equal(1, tree.index(ab));
10961096
t.equal(2, tree.index(ac));
10971097

1098+
tree.appendChild(a, {});
1099+
t.equal(2, tree.index(ac));
1100+
tree.childrenToArray(a);
1101+
t.equal(2, tree.index(ac));
1102+
10981103
t.end();
10991104
});
11001105

0 commit comments

Comments
 (0)