Skip to content

Commit 91f2b45

Browse files
Use an options argument instead of various arguments, for childrenToArray()
1 parent 595ff9a commit 91f2b45

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

lib/SymbolTree.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -252,21 +252,18 @@ class SymbolTree {
252252
* @method childrenToArray
253253
* @memberOf module:symbol-tree#
254254
* @param {Object} parent
255-
* @param {Object[]} [array=[]]
256-
* @param {Function} [filter] Function to test each object before it is added to the array.
255+
* @param {Object} [options]
256+
* @param {Object[]} [options.array=[]]
257+
* @param {Function} [options.filter] Function to test each object before it is added to the array.
257258
* Invoked with arguments (object). Should return `true` if an object
258259
* is to be included.
259-
* @param {*} [thisArg] Value to use as `this` when executing `filter`.
260+
* @param {*} [options.thisArg] Value to use as `this` when executing `filter`.
260261
* @return {Object[]}
261262
*/
262-
childrenToArray(parent, array, filter, thisArg) {
263-
if (!array) {
264-
array = [];
265-
}
266-
267-
if (!filter) {
268-
filter = returnTrue;
269-
}
263+
childrenToArray(parent, options) {
264+
const array = (options && options.array ) || [];
265+
const filter = (options && options.filter ) || returnTrue;
266+
const thisArg = (options && options.thisArg) || undefined;
270267

271268
let object = this._node(parent).first;
272269
let index = 0;

test/SymbolTree.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ test('childrenToArray', function(t) {
632632
t.deepEqual([aa, ab, ac], tree.childrenToArray(a));
633633

634634
const arr = ['a', 5];
635-
tree.childrenToArray(a, arr);
635+
tree.childrenToArray(a, {array: arr});
636636
t.deepEqual(['a', 5, aa, ab, ac], arr);
637637

638638
t.end();
@@ -659,7 +659,7 @@ test('childrenToArray with filter', function(t) {
659659
return object !== ab;
660660
};
661661

662-
t.deepEqual([aa, ac], tree.childrenToArray(a, null, filter));
662+
t.deepEqual([aa, ac], tree.childrenToArray(a, {filter: filter}));
663663

664664
const thisArg = {a: 123};
665665
const filterThis = function(object) {
@@ -668,7 +668,7 @@ test('childrenToArray with filter', function(t) {
668668
return object !== ab;
669669
};
670670

671-
t.deepEqual([aa, ac], tree.childrenToArray(a, null, filterThis, thisArg));
671+
t.deepEqual([aa, ac], tree.childrenToArray(a, {filter: filterThis, thisArg: thisArg}));
672672

673673
t.end();
674674
});

0 commit comments

Comments
 (0)