Skip to content

Commit daebded

Browse files
committed
add :empty
1 parent eebc3e1 commit daebded

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ That's it!
7171
- [ ] `:last-of-type`
7272
- [x] `:only-child`
7373
- [ ] `:only-of-type`
74-
- [ ] `:empty`
74+
- [x] `:empty`
7575
- [x] Negation pseudo-class: `*:not(paragraph)`
7676

7777
## API

lib/match-node.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ function matchPseudos (rule, node, nodeIndex, parent) {
7979
case 'only-child':
8080
return parent && parent.children.length == 1;
8181

82+
case 'empty':
83+
return node.children && !node.children.length;
84+
8285
case 'not':
8386
return !matchNode(pseudo.value.rule, node, nodeIndex, parent);
8487

test/select.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ test('structural pseudo-classes', function (t) {
205205
t.end();
206206
});
207207

208+
t.test(':empty', function (t) {
209+
t.deepEqual(select(ast, ':root:empty'), []);
210+
t.deepEqual(select(ast, 'text:empty'), []);
211+
t.deepEqual(select(ast, 'list:not(:empty)'), select(ast, 'list'));
212+
t.deepEqual(select(ast, ':empty'), select(ast, 'div > div'));
213+
t.end();
214+
});
215+
208216
t.end();
209217
});
210218

0 commit comments

Comments
 (0)