Skip to content

Commit 7f24c00

Browse files
committed
Update unist-util-is
Breaking: this removes the identity check. Previously, it was possible to pass a node in, and remove that node, as the comparison was done with strict equality (`===`). `unist-util-is@2.0.0` no longer supports this and treats a given object (or node) as a shallow partial property check. If your code relies on that, you must change it along the following lines: ```diff -remove(tree, thing); +remove(tree, node => node === thing) ``` Closes GH-1.
1 parent 0295970 commit 7f24c00

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"util"
3030
],
3131
"dependencies": {
32-
"unist-util-is": "^1.0.0"
32+
"unist-util-is": "^2.0.0"
3333
},
3434
"devDependencies": {
3535
"tape": "^4.4.0",

test/test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ var it = require('tape'),
66
u = require('unist-builder');
77

88

9-
it('should compare nodes by identity', function (t) {
9+
it('should compare nodes by partial properties', function (t) {
1010
var ast = u('node', [
11-
u('node', 'value'),
12-
u('node', 'value')
11+
u('node', 'foo'),
12+
u('node', 'bar')
1313
]);
1414
var children = ast.children;
1515
var firstChild = ast.children[0];
1616

17-
var newAst = remove(ast, ast.children[1]);
17+
var newAst = remove(ast, {value: 'bar'});
1818

1919
t.equal(newAst, ast);
2020
t.deepEqual(ast, u('node', [firstChild]));
@@ -34,7 +34,9 @@ it('should remove nodes with children', function (t) {
3434
var children = ast.children;
3535
var secondLeaf = ast.children[1];
3636

37-
var newAst = remove(ast, ast.children[0]);
37+
var newAst = remove(ast, function (node) {
38+
return node === ast.children[0];
39+
});
3840

3941
t.equal(newAst, ast);
4042
t.deepEqual(ast, u('root', [secondLeaf]));

0 commit comments

Comments
 (0)