Skip to content

Commit aab9801

Browse files
Use an options argument instead of various arguments, for preceding()
1 parent 8ae6a73 commit aab9801

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

lib/SymbolTree.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,15 @@ class SymbolTree {
174174
* @method preceding
175175
* @memberOf module:symbol-tree#
176176
* @param {Object} object
177-
* @param {Object} [treeRoot] If set, `treeRoot` must be an inclusive ancestor
177+
* @param {Object} [options]
178+
* @param {Object} [options.root] If set, `root` must be an inclusive ancestor
178179
* of the return value (or else null is returned). This check _assumes_
179180
* that `root` is also an inclusive ancestor of the given `node`
180181
* @returns {?Object}
181182
*/
182-
preceding(object, treeRoot) {
183+
preceding(object, options) {
184+
const treeRoot = options && options.root;
185+
183186
if (object === treeRoot) {
184187
return null;
185188
}

lib/TreeIterator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class TreeIterator {
3737
this[NEXT] = tree._node(value).parent;
3838
}
3939
else if (iterateFunc === 4) {
40-
this[NEXT] = tree.preceding(value, root);
40+
this[NEXT] = tree.preceding(value, {root: root});
4141
}
4242
else /*if (iterateFunc === 5)*/ {
4343
this[NEXT] = tree.following(value, root);

test/SymbolTree.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,9 @@ test('look up preceding using a specified root', function(t) {
517517

518518
tree.insertLast(aa, a);
519519

520-
t.equal(null, tree.preceding(a, a));
521-
t.equal(a , tree.preceding(aa, a));
522-
t.equal(null, tree.preceding(aa, aa));
520+
t.equal(null, tree.preceding(a , {root: a}));
521+
t.equal(a , tree.preceding(aa, {root: a}));
522+
t.equal(null, tree.preceding(aa, {root: aa}));
523523

524524
t.end();
525525
});

0 commit comments

Comments
 (0)