Skip to content

Commit 595ff9a

Browse files
Use an options argument instead of various arguments, for following()
1 parent aab9801 commit 595ff9a

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

lib/SymbolTree.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,17 @@ class SymbolTree {
207207
* @method following
208208
* @memberOf module:symbol-tree#
209209
* @param {!Object} object
210-
* @param {Object} [treeRoot] If set, `treeRoot` must be an inclusive ancestor
210+
* @param {Object} [options]
211+
* @param {Object} [options.root] If set, `root` must be an inclusive ancestor
211212
* of the return value (or else null is returned). This check _assumes_
212213
* that `root` is also an inclusive ancestor of the given `node`
213-
* @param {Boolean} [skipChildren=false] If set, ignore the childen of `object`
214+
* @param {Boolean} [options.skipChildren=false] If set, ignore the children of `object`
214215
* @returns {?Object}
215216
*/
216-
following(object, treeRoot, skipChildren) {
217+
following(object, options) {
218+
const treeRoot = options && options.root;
219+
const skipChildren = options && options.skipChildren;
220+
217221
const first = !skipChildren && this._node(object).first;
218222

219223
if (first) {
@@ -348,7 +352,7 @@ class SymbolTree {
348352
if (filter.call(thisArg, object)) {
349353
array.push(object);
350354
}
351-
object = this.following(object, root);
355+
object = this.following(object, {root: root});
352356
}
353357

354358
return array;

lib/TreeIterator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TreeIterator {
4040
this[NEXT] = tree.preceding(value, {root: root});
4141
}
4242
else /*if (iterateFunc === 5)*/ {
43-
this[NEXT] = tree.following(value, root);
43+
this[NEXT] = tree.following(value, {root: root});
4444
}
4545

4646
return {

test/SymbolTree.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,11 @@ test('following using a specified root', function(t) {
591591
tree.insertLast(aaa, aa);
592592
tree.insertAfter(b, a);
593593

594-
t.equal(null, tree.following(aaa, aaa));
595-
t.equal(null, tree.following(aaa, aa));
596-
t.equal(null, tree.following(aaa, a));
597-
t.equal(aa , tree.following(a, a));
598-
t.equal(aaa , tree.following(aa, a));
594+
t.equal(null, tree.following(aaa, {root: aaa}));
595+
t.equal(null, tree.following(aaa, {root: aa}));
596+
t.equal(null, tree.following(aaa, {root: a}));
597+
t.equal(aa , tree.following(a , {root: a}));
598+
t.equal(aaa , tree.following(aa , {root: a}));
599599

600600
t.end();
601601
});
@@ -609,7 +609,7 @@ test('following with skipChildren', function(t) {
609609
tree.insertLast(aa, a);
610610
tree.insertAfter(b, a);
611611

612-
t.equal(b, tree.following(a, null, true));
612+
t.equal(b, tree.following(a, {skipChildren: true}));
613613

614614
t.end();
615615
});

0 commit comments

Comments
 (0)