Skip to content

Commit 499860e

Browse files
Use an options argument instead of various arguments, for ancestorsToArray()
1 parent 91f2b45 commit 499860e

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

lib/SymbolTree.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,21 +291,18 @@ class SymbolTree {
291291
* @method ancestorsToArray
292292
* @memberOf module:symbol-tree#
293293
* @param {Object} object
294-
* @param {Object[]} [array=[]]
295-
* @param {Function} [filter] Function to test each object before it is added to the array.
294+
* @param {Object} [options]
295+
* @param {Object[]} [options.array=[]]
296+
* @param {Function} [options.filter] Function to test each object before it is added to the array.
296297
* Invoked with arguments (object). Should return `true` if an object
297298
* is to be included.
298-
* @param {*} [thisArg] Value to use as `this` when executing `filter`.
299+
* @param {*} [options.thisArg] Value to use as `this` when executing `filter`.
299300
* @return {Object[]}
300301
*/
301-
ancestorsToArray(object, array, filter, thisArg) {
302-
if (!array) {
303-
array = [];
304-
}
305-
306-
if (!filter) {
307-
filter = returnTrue;
308-
}
302+
ancestorsToArray(object, options) {
303+
const array = (options && options.array ) || [];
304+
const filter = (options && options.filter ) || returnTrue;
305+
const thisArg = (options && options.thisArg) || undefined;
309306

310307
let ancestor = object;
311308

test/SymbolTree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ test('ancestorsToArray', function(t) {
828828
t.deepEqual([b], tree.ancestorsToArray(b));
829829

830830
const arr = ['a', 5];
831-
tree.ancestorsToArray(abaa, arr);
831+
tree.ancestorsToArray(abaa, {array: arr});
832832
t.deepEqual(['a', 5, abaa, aba, ab, a], arr);
833833

834834
t.end();
@@ -856,7 +856,7 @@ test('ancestorsToArray with filter', function(t) {
856856
return object !== abaa && object !== ab;
857857
};
858858

859-
t.deepEqual([aba, a], tree.ancestorsToArray(abaa, null, filter, thisArg));
859+
t.deepEqual([aba, a], tree.ancestorsToArray(abaa, {filter: filter, thisArg: thisArg}));
860860

861861
t.end();
862862
});

0 commit comments

Comments
 (0)