Skip to content

Commit 5da284c

Browse files
peterbabicwooorm
andcommitted
Remove circular dependency
Closes GH-9. Closes GH-10. Co-authored-by: Peter Babič <[email protected]> Co-authored-by: Titus Wormer <[email protected]>
1 parent 2269b1c commit 5da284c

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ var any = require('./lib/any')
88
var parse = require('./lib/parse')
99

1010
function matches(selector, node) {
11-
return Boolean(any(parse(selector), node, {one: true, shallow: true})[0])
11+
return Boolean(
12+
any(parse(selector), node, {one: true, shallow: true, any: any})[0]
13+
)
1214
}
1315

1416
function select(selector, node) {
15-
return any(parse(selector), node, {one: true})[0] || null
17+
return any(parse(selector), node, {one: true, any: any})[0] || null
1618
}
1719

1820
function selectAll(selector, node) {
19-
return any(parse(selector), node, {})
21+
return any(parse(selector), node, {any: any})
2022
}

lib/any.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ function rule(query, tree, state) {
5252
scopeNodes: tree.type === 'root' ? tree.children : [tree],
5353
iterator: iterator,
5454
one: state.one,
55-
shallow: state.shallow
55+
shallow: state.shallow,
56+
any: state.any
5657
})
5758
)
5859

lib/pseudo.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module.exports = match
55
var zwitch = require('zwitch')
66
var not = require('not')
77
var convert = require('unist-util-is/convert')
8-
var anything = require('./any')
98

109
var is = convert()
1110

@@ -61,6 +60,7 @@ function match(query, node, index, parent, state) {
6160
function matches(query, node, index, parent, state) {
6261
var shallow = state.shallow
6362
var one = state.one
63+
var anything = state.any
6464
var result
6565

6666
state.one = true
@@ -160,6 +160,7 @@ function hasSelector(query, node, index, parent, state) {
160160
var one = state.one
161161
var scopeNodes = state.scopeNodes
162162
var value = appendScope(query.value)
163+
var anything = state.any
163164
var result
164165

165166
state.shallow = false

test/select-all.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,16 @@ test('select.selectAll()', function (t) {
727727
sst.end()
728728
})
729729

730+
st.test(':has', function (sst) {
731+
sst.deepEqual(
732+
selectAll('c:has(:first-child)', u('a', [u('b'), u('c', [u('d')])])),
733+
[u('c', [u('d')])],
734+
'should select a node'
735+
)
736+
737+
sst.end()
738+
})
739+
730740
st.end()
731741
})
732742

test/select.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,16 @@ test('select.select()', function (t) {
693693
sst.end()
694694
})
695695

696+
st.test(':has', function (sst) {
697+
sst.deepEqual(
698+
select('c:has(:first-child)', u('a', [u('b'), u('c', [u('d')])])),
699+
u('c', [u('d')]),
700+
'should select a node'
701+
)
702+
703+
sst.end()
704+
})
705+
696706
st.end()
697707
})
698708

0 commit comments

Comments
 (0)