Skip to content

Commit dbc7fa3

Browse files
committed
Remove support for passing a list of nodes
1 parent 7f24c00 commit dbc7fa3

File tree

6 files changed

+13
-63
lines changed

6 files changed

+13
-63
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Remove one or more nodes from [Unist] tree, mutating it.
88

99
[unist]: https://github.com/wooorm/unist
10+
[is]: https://github.com/syntax-tree/unist-util-is#api
1011

1112
[travis]: https://travis-ci.org/eush77/unist-util-remove
1213
[travis-badge]: https://travis-ci.org/eush77/unist-util-remove.svg?branch=master
@@ -80,10 +81,7 @@ remove(ast, ast)
8081
### `remove(ast, [opts], predicate)`
8182

8283
- `ast`[Unist] tree.
83-
- `predicate` — one of:
84-
- [Unist] node or array of nodes,
85-
- node type (string),
86-
- function invoked with arguments `(node, index?, parent?)`.
84+
- `predicate` — any `test` as given to [`unist-util-is`][is].
8785

8886
Iterates over `ast` in preorder traversal and removes all nodes matching `predicate` from `ast`. Returns a modified [Unist] tree.
8987

index.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ module.exports = function (ast, opts, predicate) {
99
opts = {};
1010
}
1111

12-
if (Array.isArray(predicate)) {
13-
predicate = arrayPredicate(predicate);
14-
}
1512
opts.cascade = opts.cascade || opts.cascade === undefined;
1613

1714
// Check and remove nodes recursively in preorder.
@@ -45,10 +42,3 @@ module.exports = function (ast, opts, predicate) {
4542
return node;
4643
}(ast, null, null));
4744
};
48-
49-
50-
function arrayPredicate (nodes) {
51-
return function (node) {
52-
return nodes.indexOf(node) >= 0;
53-
};
54-
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"author": "Eugene Sharygin <eush77@gmail.com>",
66
"license": "MIT",
77
"scripts": {
8-
"test": "tape test/*.js"
8+
"test": "tape test/*.js",
9+
"cov": "nyc --reporter lcov tape test/*.js"
910
},
1011
"files": [
1112
"index.js"

test/example.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@ test('example from README', function (t) {
2020
var one = ast.children[0];
2121
var four = ast.children[2];
2222

23-
var newAst = remove(ast, [
24-
ast.children[1].children[0],
25-
ast.children[1].children[1]
26-
]);
27-
t.equal(ast, newAst);
28-
t.deepEqual(ast, u('root', [
29-
u('leaf', 1),
30-
u('leaf', 4)
31-
]));
32-
t.equal(ast.children[0], one);
33-
t.equal(ast.children[1], four);
34-
3523
t.equal(remove(ast, ast), null);
3624

3725
t.end();

test/opts.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ test('opts.cascade', function (t) {
1515
u('leaf', 2)
1616
]);
1717

18-
var newAst = remove(ast, { cascade: true }, [
19-
ast.children[0].children[0],
20-
ast.children[1]
21-
]);
18+
var newAst = remove(ast, { cascade: true }, function (node) {
19+
return node === ast.children[0].children[0] || node === ast.children[1];
20+
});
2221

2322
t.equal(newAst, null);
2423
t.end();
@@ -35,10 +34,9 @@ test('opts.cascade', function (t) {
3534
var innerNode = ast.children[0];
3635
var grandChildren = ast.children[0].children;
3736

38-
var newAst = remove(ast, { cascade: false }, [
39-
ast.children[0].children[0],
40-
ast.children[1]
41-
]);
37+
var newAst = remove(ast, { cascade: false }, function (node) {
38+
return node === ast.children[0].children[0] || node === ast.children[1];
39+
});
4240

4341
t.equal(newAst, ast);
4442
t.deepEqual(ast, u('root', [

test/test.js

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,30 +59,6 @@ it('should return `null` if root node is removed', function (t) {
5959
});
6060

6161

62-
it('should accept array of nodes', function (t) {
63-
var ast = u('root', [
64-
u('leaf', 1),
65-
u('leaf', 2),
66-
u('leaf', 3),
67-
u('leaf', 4)
68-
]);
69-
var children = ast.children;
70-
var secondLeaf = ast.children[1];
71-
72-
var newAst = remove(ast, [
73-
ast.children[0],
74-
ast.children[2],
75-
ast.children[3]
76-
]);
77-
78-
t.equal(newAst, ast);
79-
t.deepEqual(ast, u('root', [secondLeaf]));
80-
t.equal(ast.children, children);
81-
t.equal(ast.children[0], secondLeaf);
82-
t.end();
83-
});
84-
85-
8662
it('should cascade remove parent nodes', function (t) {
8763
t.test(function (t) {
8864
var ast = u('root', [
@@ -111,10 +87,9 @@ it('should cascade remove parent nodes', function (t) {
11187
u('leaf', 2)
11288
]);
11389

114-
var newAst = remove(ast, [
115-
ast.children[0].children[0],
116-
ast.children[1]
117-
]);
90+
var newAst = remove(ast, function (node) {
91+
return node === ast.children[0].children[0] || node === ast.children[1];
92+
});
11893

11994
t.equal(newAst, null);
12095
t.end();

0 commit comments

Comments
 (0)