Skip to content

Commit b5b198c

Browse files
committed
remove context argument
The optional `context` argument does not add any substantial utility (beyond `Function.prototype.bind` or fat arrows) to warrant the monstrosity of the resulting interface.
1 parent ff3abf8 commit b5b198c

File tree

3 files changed

+3
-16
lines changed

3 files changed

+3
-16
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,10 @@ filter(ast, (node) => node.type != 'leaf' || node.value % 2 == 0)
7676

7777
## API
7878

79-
### `filter(ast, [opts], predicate, [context])`
79+
### `filter(ast, [opts], predicate)`
8080

8181
- `ast`[Unist] tree.
8282
- `predicate` — Function invoked with arguments `(node, index?, parent?)` or string (type test) or node (identity test) to test each node. See [unist-util-is] for details. In a function form, return `true` to keep the node, `false` otherwise.
83-
- `context` — Optional. Value to use as `this` when executing `predicate`.
8483

8584
Executes `predicate` for each node in preorder tree traversal. Returns a new tree (or `null`) with nodes for which `predicate` returned `true`.
8685

index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ var flatmap = require('flatmap'),
44
is = require('unist-util-is');
55

66

7-
module.exports = function (ast, opts, predicate, context) {
7+
module.exports = function (ast, opts, predicate) {
88
if (arguments.length == 2) {
9-
context = predicate;
109
predicate = opts;
1110
opts = {};
1211
}
1312
opts.cascade = opts.cascade || opts.cascade === undefined;
1413

1514
return (function preorder (node, index, parent) {
16-
if (!is(predicate, node, index, parent, context)) {
15+
if (!is(predicate, node, index, parent)) {
1716
return null;
1817
}
1918

test/test.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,6 @@ it('should call iterator with `index` and `parent` args', function (t) {
112112
});
113113

114114

115-
it('should call iterator in a context passed in as the last arg', function (t) {
116-
var context = Object.create(null);
117-
118-
filter(u('root'), function () {
119-
t.equal(this, context);
120-
}, context);
121-
122-
t.end();
123-
});
124-
125-
126115
it('should support type and node tests', function (t) {
127116
var ast = u('node', [
128117
u('node', [

0 commit comments

Comments
 (0)