Skip to content

Commit e6832b7

Browse files
committed
preserve initially empty nodes
1 parent 9abe8df commit e6832b7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = function (ast, opts, predicate) {
2828
return preorder(child, index, node);
2929
});
3030

31-
if (!newNode.children.length && opts.cascade) {
31+
if (opts.cascade && !newNode.children.length && node.children.length) {
3232
return null;
3333
}
3434
}

test/test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ it('should cascade remove parent nodes', function (t) {
8484
});
8585

8686

87+
it('should not cascade-remove nodes that were empty initially', function (t) {
88+
var ast = u('node', [
89+
u('node', []),
90+
u('node', [
91+
u('leaf')
92+
])
93+
]);
94+
95+
ast = filter(ast, 'node');
96+
97+
t.deepEqual(ast, u('node', [
98+
u('node', [])
99+
]));
100+
t.end();
101+
});
102+
103+
87104
it('should call iterator with `index` and `parent` args', function (t) {
88105
var ast = u('root', [
89106
u('node', [

0 commit comments

Comments
 (0)