Skip to content

Commit 023c924

Browse files
Optionally skip children when looking for following siblings
1 parent 988b7d5 commit 023c924

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/SymbolTree.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,11 @@ module.exports = class SymbolTree {
150150
* @param {Object} [treeRoot] If set, `treeRoot` must be an inclusive ancestor
151151
* of the return value (or else null is returned). This check _assumes_
152152
* that `root` is also an inclusive ancestor of the given `node`
153+
* @param {Boolean} [skipChildren=false] If set, ignore the childen of `object`
153154
* @returns {?Object}
154155
*/
155-
following(object, treeRoot) {
156-
if (this._node(object).first) {
156+
following(object, treeRoot, skipChildren) {
157+
if (!skipChildren && this._node(object).first) {
157158
return this._node(object).first;
158159
}
159160

test/SymbolTree.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,3 +579,17 @@ test('following using a specified root', function(t) {
579579

580580
t.end();
581581
});
582+
583+
test('following with skipChildren', function(t) {
584+
const tree = new SymbolTree();
585+
const a = {};
586+
const aa = {};
587+
const b = {};
588+
589+
tree.insertLast(aa, a);
590+
tree.insertAfter(b, a);
591+
592+
t.equal(b, tree.following(a, null, true));
593+
594+
t.end();
595+
});

0 commit comments

Comments
 (0)