Skip to content

Commit 4eb6930

Browse files
committed
Fix bug where descendant selector wasn’t working
1 parent 7aa9dfe commit 4eb6930

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/nest.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var zwitch = require('zwitch');
55
module.exports = zwitch('nestingOperator');
66

77
var own = {}.hasOwnProperty;
8+
var slice = [].slice;
89

910
var handle = module.exports;
1011
var handlers = handle.handlers;
@@ -43,16 +44,18 @@ function descendant(query, node, index, parent, state) {
4344

4445
state.iterator = iterator;
4546

46-
return child(query, node, index, parent, state);
47+
child.apply(this, arguments);
4748

48-
function iterator(subq, node, index) {
49+
function iterator() {
50+
state.iterator = prev;
4951
prev.apply(this, arguments);
52+
state.iterator = iterator;
5053

5154
if (state.one && state.found) {
5255
return;
5356
}
5457

55-
child(query, node, index, node, state);
58+
child.apply(this, [query].concat(slice.call(arguments, 1)));
5659
}
5760
}
5861

test/select-all.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ test('select.selectAll()', function (t) {
124124
'should return deep matches'
125125
);
126126

127+
st.deepEqual(
128+
selectAll('b s', h('p', [
129+
h('b', h('s', '1')),
130+
h('i', h('s', '2'))
131+
])),
132+
[h('s', '1')],
133+
'should not match outside other matches'
134+
);
135+
127136
st.end();
128137
});
129138

0 commit comments

Comments
 (0)