Skip to content

Commit bfe315f

Browse files
Use an options argument instead of various arguments, for treeToArray()
1 parent 499860e commit bfe315f

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
@@ -324,21 +324,18 @@ class SymbolTree {
324324
* @method treeToArray
325325
* @memberOf module:symbol-tree#
326326
* @param {Object} root
327-
* @param {Object[]} [array=[]]
328-
* @param {Function} [filter] Function to test each object before it is added to the array.
327+
* @param {Object} [options]
328+
* @param {Object[]} [options.array=[]]
329+
* @param {Function} [options.filter] Function to test each object before it is added to the array.
329330
* Invoked with arguments (object). Should return `true` if an object
330331
* is to be included.
331-
* @param {*} [thisArg] Value to use as `this` when executing `filter`.
332+
* @param {*} [options.thisArg] Value to use as `this` when executing `filter`.
332333
* @return {Object[]}
333334
*/
334-
treeToArray(root, array, filter, thisArg) {
335-
if (!array) {
336-
array = [];
337-
}
338-
339-
if (!filter) {
340-
filter = returnTrue;
341-
}
335+
treeToArray(root, options) {
336+
const array = (options && options.array ) || [];
337+
const filter = (options && options.filter ) || returnTrue;
338+
const thisArg = (options && options.thisArg) || undefined;
342339

343340
let object = root;
344341

test/SymbolTree.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ test('treeToArray', function(t) {
907907
t.deepEqual([a, aa, ab, aba, abaa], tree.treeToArray(a));
908908

909909
const arr = ['a', 5];
910-
tree.treeToArray(a, arr);
910+
tree.treeToArray(a, {array: arr});
911911
t.deepEqual(['a', 5, a, aa, ab, aba, abaa], arr);
912912

913913
t.end();
@@ -934,7 +934,7 @@ test('treeToArray with filter', function(t) {
934934
return object !== a && object !== aba;
935935
};
936936

937-
t.deepEqual([aa, ab, abaa], tree.treeToArray(a, null, filter));
937+
t.deepEqual([aa, ab, abaa], tree.treeToArray(a, {filter: filter}));
938938

939939
const thisArg = {foo: 'bar'};
940940
const filterThis = function(object) {
@@ -943,7 +943,7 @@ test('treeToArray with filter', function(t) {
943943
return object !== a && object !== aba;
944944
};
945945

946-
t.deepEqual([aa, ab, abaa], tree.treeToArray(a, null, filterThis, thisArg));
946+
t.deepEqual([aa, ab, abaa], tree.treeToArray(a, {filter: filterThis, thisArg: thisArg}));
947947

948948
t.end();
949949
});

0 commit comments

Comments
 (0)