Skip to content

Commit b6d28e7

Browse files
committed
preserve initially empty nodes
1 parent 47b0a0c commit b6d28e7

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
@@ -20,7 +20,7 @@ module.exports = function (ast, opts, predicate) {
2020
if (is(predicate, node, nodeIndex, parent)) {
2121
return null;
2222
}
23-
if (!node.children) {
23+
if (!node.children || !node.children.length) {
2424
return node;
2525
}
2626

test/test.js

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

122122

123+
it('should not cascade-remove nodes that were empty initially', function (t) {
124+
var ast = u('node', [
125+
u('node', []),
126+
u('node', [
127+
u('leaf')
128+
])
129+
]);
130+
131+
ast = remove(ast, 'leaf');
132+
133+
t.deepEqual(ast, u('node', [
134+
u('node', [])
135+
]));
136+
t.end();
137+
});
138+
139+
123140
it('should support type tests and predicate functions', function (t) {
124141
t.test(function (t) {
125142
var ast = u('node', [

0 commit comments

Comments
 (0)