Skip to content

Commit 465234f

Browse files
committedApr 28, 2021
Use ESM
·
6.0.45.0.0
1 parent 4683510 commit 465234f

21 files changed

+271
-345
lines changed
 

‎.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
.DS_Store
22
*.log
3-
.nyc_output/
43
coverage/
54
node_modules/
6-
hast-util-select.js
7-
hast-util-select.min.js
85
yarn.lock

‎.prettierignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
coverage/
2-
hast-util-select.js
3-
hast-util-select.min.js
4-
*.json
52
*.md

‎index.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
'use strict'
1+
import {any} from './lib/any.js'
2+
import {parse} from './lib/parse.js'
23

3-
exports.matches = matches
4-
exports.selectAll = selectAll
5-
exports.select = select
6-
7-
var any = require('./lib/any')
8-
var parse = require('./lib/parse')
9-
10-
function matches(selector, node, space) {
4+
export function matches(selector, node, space) {
115
return Boolean(
12-
any(parse(selector), node, {space: space, one: true, shallow: true})[0]
6+
any(parse(selector), node, {space, one: true, shallow: true})[0]
137
)
148
}
159

16-
function select(selector, node, space) {
17-
return any(parse(selector), node, {space: space, one: true})[0] || null
10+
export function select(selector, node, space) {
11+
return any(parse(selector), node, {space, one: true})[0] || null
1812
}
1913

20-
function selectAll(selector, node, space) {
21-
return any(parse(selector), node, {space: space})
14+
export function selectAll(selector, node, space) {
15+
return any(parse(selector), node, {space})
2216
}

‎lib/any.js

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
1-
'use strict'
2-
3-
module.exports = match
4-
5-
var html = require('property-information/html')
6-
var svg = require('property-information/svg')
7-
var zwitch = require('zwitch')
8-
var enter = require('./enter-state')
9-
var nest = require('./nest')
10-
var pseudo = require('./pseudo')
11-
var test = require('./test')
1+
import {html, svg} from 'property-information'
2+
import {zwitch} from 'zwitch'
3+
import {enterState} from './enter-state.js'
4+
import {nest} from './nest.js'
5+
import {pseudo} from './pseudo.js'
6+
import {test} from './test.js'
127

138
var type = zwitch('type', {
149
unknown: unknownType,
1510
invalid: invalidType,
16-
handlers: {
17-
selectors: selectors,
18-
ruleSet: ruleSet,
19-
rule: rule
20-
}
11+
handlers: {selectors, ruleSet, rule}
2112
})
2213

23-
function match(query, node, state) {
14+
export function any(query, node, state) {
2415
return query && node ? type(query, node, state) : []
2516
}
2617

@@ -57,7 +48,7 @@ function rule(query, tree, state) {
5748
direction: 'ltr',
5849
editableOrEditingHost: false,
5950
scopeElements: tree.type === 'root' ? tree.children : [tree],
60-
iterator: iterator,
51+
iterator,
6152
one: state.one,
6253
shallow: state.shallow
6354
})
@@ -66,7 +57,7 @@ function rule(query, tree, state) {
6657
return collect.result
6758

6859
function iterator(query, node, index, parent, state) {
69-
var exit = enter(state, node)
60+
var exit = enterState(state, node)
7061

7162
if (test(query, node, index, parent, state)) {
7263
if (query.rule) {
@@ -85,7 +76,7 @@ function rule(query, tree, state) {
8576
var index = -1
8677

8778
while (++index < pseudos.length) {
88-
if (pseudo.needsIndex.indexOf(pseudos[index].name) > -1) {
79+
if (pseudo.needsIndex.includes(pseudos[index].name)) {
8980
state.index = true
9081
break
9182
}
@@ -95,12 +86,14 @@ function rule(query, tree, state) {
9586
}
9687
}
9788

98-
/* istanbul ignore next - Shouldn’t be invoked, all data is handled. */
89+
// Shouldn’t be called, all data is handled.
90+
/* c8 ignore next 3 */
9991
function unknownType(query) {
10092
throw new Error('Unknown type `' + query.type + '`')
10193
}
10294

103-
/* istanbul ignore next - Shouldn’t be invoked, parser gives correct data. */
95+
// Shouldn’t be called, parser gives correct data.
96+
/* c8 ignore next 3 */
10497
function invalidType() {
10598
throw new Error('Invalid type')
10699
}
@@ -127,12 +120,13 @@ function collector(one) {
127120

128121
function collectOne(element) {
129122
if (one) {
130-
/* istanbul ignore if - shouldn’t happen, safeguards performance problems. */
123+
// Shouldn’t happen, safeguards performance problems.
124+
/* c8 ignore next */
131125
if (found) throw new Error('Cannot collect multiple nodes')
132126
found = true
133127
}
134128

135-
if (result.indexOf(element) < 0) result.push(element)
129+
if (!result.includes(element)) result.push(element)
136130
}
137131
}
138132
}

‎lib/attribute.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
'use strict'
2-
3-
module.exports = match
4-
5-
var commas = require('comma-separated-tokens')
6-
var has = require('hast-util-has-property')
7-
var find = require('property-information/find')
8-
var spaces = require('space-separated-tokens')
9-
var zwitch = require('zwitch')
1+
import {stringify as commas} from 'comma-separated-tokens'
2+
import {hasProperty} from 'hast-util-has-property'
3+
import {find} from 'property-information'
4+
import {stringify as spaces} from 'space-separated-tokens'
5+
import {zwitch} from 'zwitch'
106

117
var handle = zwitch('operator', {
128
unknown: unknownOperator,
@@ -21,7 +17,7 @@ var handle = zwitch('operator', {
2117
}
2218
})
2319

24-
function match(query, node, schema) {
20+
export function attribute(query, node, schema) {
2521
var attrs = query.attrs
2622
var index = -1
2723

@@ -34,13 +30,13 @@ function match(query, node, schema) {
3430

3531
// `[attr]`
3632
function exists(query, node, info) {
37-
return has(node, info.property)
33+
return hasProperty(node, info.property)
3834
}
3935

4036
// `[attr=value]`
4137
function exact(query, node, info) {
4238
return (
43-
has(node, info.property) &&
39+
hasProperty(node, info.property) &&
4440
normalizeValue(node.properties[info.property], info) === query.value
4541
)
4642
}
@@ -55,10 +51,11 @@ function spaceSeparatedList(query, node, info) {
5551
(!info.commaSeparated &&
5652
value &&
5753
typeof value === 'object' &&
58-
value.indexOf(query.value) > -1) ||
54+
value.includes(query.value)) ||
5955
// For all other values (including comma-separated lists), return whether this
6056
// is an exact match.
61-
(has(node, info.property) && normalizeValue(value, info) === query.value)
57+
(hasProperty(node, info.property) &&
58+
normalizeValue(value, info) === query.value)
6259
)
6360
}
6461

@@ -67,7 +64,7 @@ function exactOrPrefix(query, node, info) {
6764
var value = normalizeValue(node.properties[info.property], info)
6865

6966
return (
70-
has(node, info.property) &&
67+
hasProperty(node, info.property) &&
7168
(value === query.value ||
7269
(value.slice(0, query.value.length) === query.value &&
7370
value.charAt(query.value.length) === '-'))
@@ -77,7 +74,7 @@ function exactOrPrefix(query, node, info) {
7774
// `[attr^=value]`
7875
function begins(query, node, info) {
7976
return (
80-
has(node, info.property) &&
77+
hasProperty(node, info.property) &&
8178
normalizeValue(node.properties[info.property], info).slice(
8279
0,
8380
query.value.length
@@ -88,7 +85,7 @@ function begins(query, node, info) {
8885
// `[attr$=value]`
8986
function ends(query, node, info) {
9087
return (
91-
has(node, info.property) &&
88+
hasProperty(node, info.property) &&
9289
normalizeValue(node.properties[info.property], info).slice(
9390
-query.value.length
9491
) === query.value
@@ -98,13 +95,13 @@ function ends(query, node, info) {
9895
// `[attr*=value]`
9996
function contains(query, node, info) {
10097
return (
101-
has(node, info.property) &&
102-
normalizeValue(node.properties[info.property], info).indexOf(query.value) >
103-
-1
98+
hasProperty(node, info.property) &&
99+
normalizeValue(node.properties[info.property], info).includes(query.value)
104100
)
105101
}
106102

107-
/* istanbul ignore next - Shouldn’t be invoked, Parser throws an error instead. */
103+
// Shouldn’t be called, Parser throws an error instead.
104+
/* c8 ignore next 3 */
108105
function unknownOperator(query) {
109106
throw new Error('Unknown operator `' + query.operator + '`')
110107
}
@@ -120,7 +117,7 @@ function normalizeValue(value, info) {
120117
}
121118

122119
if (typeof value === 'object' && 'length' in value) {
123-
return (info.commaSeparated ? commas.stringify : spaces.stringify)(value)
120+
return (info.commaSeparated ? commas : spaces)(value)
124121
}
125122

126123
return value

‎lib/class-name.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
'use strict'
2-
3-
module.exports = match
4-
5-
function match(query, node) {
1+
export function className(query, node) {
62
var value = node.properties.className || []
73
var index = -1
84

95
while (++index < query.classNames.length) {
10-
if (value.indexOf(query.classNames[index]) < 0) return
6+
if (!value.includes(query.classNames[index])) return
117
}
128

139
return true

‎lib/enter-state.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
'use strict'
2-
3-
module.exports = enter
4-
5-
var direction = require('direction')
6-
var is = require('hast-util-is-element')
7-
var toString = require('hast-util-to-string')
8-
var svg = require('property-information/svg')
9-
var visit = require('unist-util-visit')
1+
import {direction} from 'direction'
2+
import {isElement} from 'hast-util-is-element'
3+
import toString from 'hast-util-to-string'
4+
import {svg} from 'property-information'
5+
import {visit, EXIT, SKIP} from 'unist-util-visit'
106

117
// eslint-disable-next-line complexity
12-
function enter(state, node) {
8+
export function enterState(state, node) {
139
var schema = state.schema
1410
var language = state.language
1511
var currentDirection = state.direction
@@ -25,7 +21,7 @@ function enter(state, node) {
2521
type = node.properties.type || 'text'
2622
dir = dirProperty(node)
2723

28-
if (lang != null) {
24+
if (lang !== undefined && lang !== null) {
2925
state.language = lang
3026
found = true
3127
}
@@ -36,7 +32,7 @@ function enter(state, node) {
3632
found = true
3733
}
3834

39-
if (is(node, 'svg')) {
35+
if (isElement(node, 'svg')) {
4036
state.schema = svg
4137
found = true
4238
}
@@ -49,18 +45,18 @@ function enter(state, node) {
4945
// Explicit `[dir=ltr]`.
5046
dir === 'ltr' ||
5147
// HTML with an invalid or no `[dir]`.
52-
(dir !== 'auto' && is(node, 'html')) ||
48+
(dir !== 'auto' && isElement(node, 'html')) ||
5349
// `input[type=tel]` with an invalid or no `[dir]`.
54-
(dir !== 'auto' && is(node, 'input') && type === 'tel')
50+
(dir !== 'auto' && isElement(node, 'input') && type === 'tel')
5551
) {
5652
dirInferred = 'ltr'
5753
// `[dir=auto]` or `bdi` with an invalid or no `[dir]`.
58-
} else if (dir === 'auto' || is(node, 'bdi')) {
59-
if (is(node, 'textarea')) {
54+
} else if (dir === 'auto' || isElement(node, 'bdi')) {
55+
if (isElement(node, 'textarea')) {
6056
// Check contents of `<textarea>`.
6157
dirInferred = dirBidi(toString(node))
6258
} else if (
63-
is(node, 'input') &&
59+
isElement(node, 'input') &&
6460
(type === 'email' ||
6561
type === 'search' ||
6662
type === 'tel' ||
@@ -100,14 +96,15 @@ function enter(state, node) {
10096
function inferDirectionality(child) {
10197
if (child.type === 'text') {
10298
dirInferred = dirBidi(child.value)
103-
return dirInferred ? visit.EXIT : null
99+
return dirInferred ? EXIT : null
104100
}
105101

106102
if (
107103
child !== node &&
108-
(is(child, ['bdi', 'script', 'style', 'textare']) || dirProperty(child))
104+
(isElement(child, ['bdi', 'script', 'style', 'textare']) ||
105+
dirProperty(child))
109106
) {
110-
return visit.SKIP
107+
return SKIP
111108
}
112109
}
113110
}

‎lib/id.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
'use strict'
2-
3-
module.exports = match
4-
5-
function match(query, node) {
1+
export function id(query, node) {
62
return node.properties.id === query.id
73
}

‎lib/name.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
'use strict'
2-
3-
module.exports = match
4-
5-
function match(query, node) {
1+
export function name(query, node) {
62
return query.tagName === '*' || query.tagName === node.tagName
73
}

‎lib/nest.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
'use strict'
2-
3-
module.exports = match
4-
5-
var zwitch = require('zwitch')
6-
var enter = require('./enter-state')
1+
import {zwitch} from 'zwitch'
2+
import {enterState} from './enter-state.js'
73

84
var own = {}.hasOwnProperty
95

@@ -18,59 +14,62 @@ var handle = zwitch('nestingOperator', {
1814
}
1915
})
2016

21-
function match(query, node, index, parent, state) {
17+
export function nest(query, node, index, parent, state) {
2218
return handle(query, node, index, parent, state)
2319
}
2420

25-
/* istanbul ignore next - Shouldn’t be invoked, parser gives correct data. */
21+
// Shouldn’t be called, parser gives correct data.
22+
/* c8 ignore next 3 */
2623
function unknownNesting(query) {
2724
throw new Error('Unexpected nesting `' + query.nestingOperator + '`')
2825
}
2926

3027
function topScan(query, node, index, parent, state) {
31-
/* istanbul ignore if - Shouldn’t happen. */
28+
// Shouldn’t happen.
29+
/* c8 ignore next 3 */
3230
if (parent) {
3331
throw new Error('topScan is supposed to be called from the root node')
3432
}
3533

36-
state.iterator.apply(null, arguments)
34+
state.iterator(...arguments)
3735

38-
if (!state.shallow) descendant.apply(null, arguments)
36+
if (!state.shallow) descendant(...arguments)
3937
}
4038

4139
function descendant(query, node, index, parent, state) {
4240
var previous = state.iterator
4341

4442
state.iterator = iterator
4543

46-
child.apply(this, arguments)
44+
child(...arguments)
4745

48-
function iterator(_, node, index, parent, state) {
46+
function iterator(_, ...rest) {
4947
state.iterator = previous
50-
previous.apply(this, arguments)
48+
previous(...arguments)
5149
state.iterator = iterator
5250

5351
if (state.one && state.found) return
5452

55-
child.call(this, query, node, index, parent, state)
53+
child(query, ...rest)
5654
}
5755
}
5856

5957
function child(query, node, index, parent, state) {
60-
if (!node.children || !node.children.length) return
58+
if (!node.children || node.children.length === 0) return
6159
indexedSearch(query, node, state)
6260
}
6361

6462
function nextSibling(query, node, index, parent, state) {
65-
/* istanbul ignore if - Shouldn’t happen. */
63+
// Shouldn’t happen.
64+
/* c8 ignore next */
6665
if (!parent) return
6766
indexedSearch(query, parent, state, index + 1, true)
6867
}
6968

7069
function subsequentSibling(query, node, index, parent, state) {
71-
/* istanbul ignore if - Shouldn’t happen. */
70+
// Shouldn’t happen.
71+
/* c8 ignore next */
7272
if (!parent) return
73-
7473
indexedSearch(query, parent, state, index + 1)
7574
}
7675

@@ -84,7 +83,7 @@ function indexedSearch(query, parent, state, from, firstElementOnly) {
8483
var index = -1
8584

8685
// Start looking at `from`
87-
if (from == null) from = 0
86+
if (from === undefined || from === null) from = 0
8887

8988
// Exit if there are no further nodes.
9089
if (from >= children.length) return
@@ -143,7 +142,7 @@ function indexedSearch(query, parent, state, from, firstElementOnly) {
143142
}
144143

145144
function add(node, childIndex) {
146-
var exit = enter(state, node)
145+
var exit = enterState(state, node)
147146
state.iterator(query, node, childIndex, parent, state)
148147
exit()
149148
}

‎lib/parse.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
'use strict'
1+
import {CssSelectorParser} from 'css-selector-parser'
2+
import fauxEsmNthCheck from 'nth-check'
3+
import {zwitch} from 'zwitch'
24

3-
module.exports = parse
5+
var nthCheck = fauxEsmNthCheck.default
46

5-
var Parser = require('css-selector-parser').CssSelectorParser
6-
var nthCheck = require('nth-check').default
7-
var zwitch = require('zwitch')
7+
var nth = new Set([
8+
'nth-child',
9+
'nth-last-child',
10+
'nth-of-type',
11+
'nth-last-of-type'
12+
])
813

9-
var nth = ['nth-child', 'nth-last-child', 'nth-of-type', 'nth-last-of-type']
10-
11-
var parser = new Parser()
14+
var parser = new CssSelectorParser()
1215

1316
var compile = zwitch('type', {
14-
handlers: {
15-
selectors: selectors,
16-
ruleSet: ruleSet,
17-
rule: rule
18-
}
17+
handlers: {selectors, ruleSet, rule}
1918
})
2019

2120
parser.registerAttrEqualityMods('~', '|', '^', '$', '*')
2221
parser.registerSelectorPseudos('any', 'matches', 'not', 'has')
2322
parser.registerNestingOperators('>', '+', '~')
2423

25-
function parse(selector) {
24+
export function parse(selector) {
2625
if (typeof selector !== 'string') {
27-
throw new Error('Expected `string` as selector, not `' + selector + '`')
26+
throw new TypeError('Expected `string` as selector, not `' + selector + '`')
2827
}
2928

3029
return compile(parser.parse(selector))
@@ -53,7 +52,7 @@ function rule(query) {
5352
while (++index < pseudos.length) {
5453
pseudo = pseudos[index]
5554

56-
if (nth.indexOf(pseudo.name) > -1) {
55+
if (nth.has(pseudo.name)) {
5756
pseudo.value = nthCheck(pseudo.value)
5857
pseudo.valueType = 'function'
5958
}

‎lib/pseudo.js

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
1-
'use strict'
2-
3-
module.exports = match
4-
5-
var bcp47Match = require('bcp-47-match')
6-
var commaSeparated = require('comma-separated-tokens')
7-
var has = require('hast-util-has-property')
8-
var is = require('hast-util-is-element')
9-
var whitespace = require('hast-util-whitespace')
10-
var not = require('not')
11-
var zwitch = require('zwitch')
12-
var anything = require('./any')
1+
import {extendedFilter} from 'bcp-47-match'
2+
import {parse as commas} from 'comma-separated-tokens'
3+
import {hasProperty} from 'hast-util-has-property'
4+
import {isElement} from 'hast-util-is-element'
5+
import {whitespace} from 'hast-util-whitespace'
6+
import not from 'not'
7+
import {zwitch} from 'zwitch'
8+
import {any} from './any.js'
139

1410
var handle = zwitch('name', {
1511
unknown: unknownPseudo,
1612
invalid: invalidPseudo,
1713
handlers: {
1814
any: matches,
1915
'any-link': anyLink,
20-
blank: blank,
21-
checked: checked,
22-
dir: dir,
23-
disabled: disabled,
24-
empty: empty,
16+
blank,
17+
checked,
18+
dir,
19+
disabled,
20+
empty,
2521
enabled: not(disabled),
2622
'first-child': firstChild,
2723
'first-of-type': firstOfType,
28-
has: hasSelector,
29-
lang: lang,
24+
has,
25+
lang,
3026
'last-child': lastChild,
3127
'last-of-type': lastOfType,
32-
matches: matches,
28+
matches,
3329
not: not(matches),
3430
'nth-child': nthChild,
3531
'nth-last-child': nthLastChild,
@@ -40,13 +36,13 @@ var handle = zwitch('name', {
4036
optional: not(required),
4137
'read-only': not(readWrite),
4238
'read-write': readWrite,
43-
required: required,
44-
root: root,
45-
scope: scope
39+
required,
40+
root,
41+
scope
4642
}
4743
})
4844

49-
match.needsIndex = [
45+
pseudo.needsIndex = [
5046
'first-child',
5147
'first-of-type',
5248
'last-child',
@@ -59,7 +55,7 @@ match.needsIndex = [
5955
'only-of-type'
6056
]
6157

62-
function match(query, node, index, parent, state) {
58+
export function pseudo(query, node, index, parent, state) {
6359
var pseudos = query.pseudos
6460
var offset = -1
6561

@@ -78,7 +74,7 @@ function matches(query, node, index, parent, state) {
7874
state.shallow = true
7975
state.one = true
8076

81-
result = anything(query.value, node, state)[0] === node
77+
result = any(query.value, node, state)[0] === node
8278

8379
state.shallow = shallow
8480
state.one = one
@@ -87,19 +83,19 @@ function matches(query, node, index, parent, state) {
8783
}
8884

8985
function anyLink(query, node) {
90-
return is(node, ['a', 'area', 'link']) && has(node, 'href')
86+
return isElement(node, ['a', 'area', 'link']) && hasProperty(node, 'href')
9187
}
9288

9389
function checked(query, node) {
94-
if (is(node, ['input', 'menuitem'])) {
90+
if (isElement(node, ['input', 'menuitem'])) {
9591
return (
9692
(node.properties.type === 'checkbox' ||
9793
node.properties.type === 'radio') &&
98-
has(node, 'checked')
94+
hasProperty(node, 'checked')
9995
)
10096
}
10197

102-
if (is(node, 'option')) return has(node, 'selected')
98+
if (isElement(node, 'option')) return hasProperty(node, 'selected')
10399
}
104100

105101
function dir(query, node, index, parent, state) {
@@ -108,7 +104,7 @@ function dir(query, node, index, parent, state) {
108104

109105
function disabled(query, node) {
110106
return (
111-
is(node, [
107+
isElement(node, [
112108
'button',
113109
'input',
114110
'select',
@@ -117,30 +113,33 @@ function disabled(query, node) {
117113
'option',
118114
'menuitem',
119115
'fieldset'
120-
]) && has(node, 'disabled')
116+
]) && hasProperty(node, 'disabled')
121117
)
122118
}
123119

124120
function required(query, node) {
125-
return is(node, ['input', 'textarea', 'select']) && has(node, 'required')
121+
return (
122+
isElement(node, ['input', 'textarea', 'select']) &&
123+
hasProperty(node, 'required')
124+
)
126125
}
127126

128127
function readWrite(query, node, index, parent, state) {
129-
return is(node, ['input', 'textarea'])
130-
? !has(node, 'readOnly') && !has(node, 'disabled')
128+
return isElement(node, ['input', 'textarea'])
129+
? !hasProperty(node, 'readOnly') && !hasProperty(node, 'disabled')
131130
: state.editableOrEditingHost
132131
}
133132

134133
function root(query, node, index, parent, state) {
135134
return (
136135
(!parent || parent.type === 'root') &&
137136
(state.schema.space === 'html' || state.schema.space === 'svg') &&
138-
is(node, ['html', 'svg'])
137+
isElement(node, ['html', 'svg'])
139138
)
140139
}
141140

142141
function scope(query, node, index, parent, state) {
143-
return is(node) && state.scopeElements.indexOf(node) > -1
142+
return isElement(node) && state.scopeElements.includes(node)
144143
}
145144

146145
function empty(query, node) {
@@ -169,9 +168,9 @@ function firstChild(query, node, index, parent, state) {
169168
function lang(query, node, index, parent, state) {
170169
return (
171170
state.language !== '' &&
172-
state.language != null &&
173-
bcp47Match.extendedFilter(state.language, commaSeparated.parse(query.value))
174-
.length
171+
state.language !== undefined &&
172+
state.language !== null &&
173+
extendedFilter(state.language, commas(query.value)).length > 0
175174
)
176175
}
177176

@@ -229,7 +228,8 @@ function someChildren(node, check) {
229228
}
230229
}
231230

232-
/* istanbul ignore next - Shouldn’t be invoked, parser gives correct data. */
231+
// Shouldn’t be called, parser gives correct data.
232+
/* c8 ignore next 3 */
233233
function invalidPseudo() {
234234
throw new Error('Invalid pseudo-selector')
235235
}
@@ -248,7 +248,7 @@ function assertDeep(state, query) {
248248
}
249249
}
250250

251-
function hasSelector(query, node, index, parent, state) {
251+
function has(query, node, index, parent, state) {
252252
var shallow = state.shallow
253253
var one = state.one
254254
var scopeElements = state.scopeElements
@@ -259,7 +259,7 @@ function hasSelector(query, node, index, parent, state) {
259259
state.one = true
260260
state.scopeElements = [node]
261261

262-
result = anything(value, node, state)[0]
262+
result = any(value, node, state)[0]
263263

264264
state.shallow = shallow
265265
state.one = one
@@ -285,7 +285,7 @@ function appendScope(value) {
285285
) {
286286
selector.selectors[index] = {
287287
type: 'rule',
288-
rule: rule,
288+
rule,
289289
pseudos: [{name: 'scope'}]
290290
}
291291
}

‎lib/test.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
'use strict'
1+
import {attribute} from './attribute.js'
2+
import {className} from './class-name.js'
3+
import {id} from './id.js'
4+
import {name} from './name.js'
5+
import {pseudo} from './pseudo.js'
26

3-
module.exports = test
4-
5-
var attributes = require('./attribute')
6-
var classNames = require('./class-name')
7-
var id = require('./id')
8-
var name = require('./name')
9-
var pseudos = require('./pseudo')
10-
11-
function test(query, node, index, parent, state) {
7+
export function test(query, node, index, parent, state) {
128
return (
139
node &&
1410
node.type === 'element' &&
1511
(!query.tagName || name(query, node)) &&
16-
(!query.classNames || classNames(query, node)) &&
12+
(!query.classNames || className(query, node)) &&
1713
(!query.id || id(query, node)) &&
18-
(!query.attrs || attributes(query, node, state.schema)) &&
19-
(!query.pseudos || pseudos(query, node, index, parent, state))
14+
(!query.attrs || attribute(query, node, state.schema)) &&
15+
(!query.pseudos || pseudo(query, node, index, parent, state))
2016
)
2117
}

‎package.json

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -28,52 +28,44 @@
2828
"contributors": [
2929
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
3030
],
31+
"sideEffects": false,
32+
"type": "module",
33+
"main": "index.js",
34+
"files": [
35+
"lib/",
36+
"index.js"
37+
],
3138
"dependencies": {
32-
"bcp-47-match": "^1.0.0",
33-
"comma-separated-tokens": "^1.0.0",
39+
"bcp-47-match": "^2.0.0",
40+
"comma-separated-tokens": "^2.0.0",
3441
"css-selector-parser": "^1.0.0",
35-
"direction": "^1.0.0",
36-
"hast-util-has-property": "^1.0.0",
37-
"hast-util-is-element": "^1.0.0",
42+
"direction": "^2.0.0",
43+
"hast-util-has-property": "^2.0.0",
44+
"hast-util-is-element": "^2.0.0",
3845
"hast-util-to-string": "^1.0.0",
39-
"hast-util-whitespace": "^1.0.0",
46+
"hast-util-whitespace": "^2.0.0",
4047
"not": "^0.1.0",
4148
"nth-check": "^2.0.0",
42-
"property-information": "^5.0.0",
43-
"space-separated-tokens": "^1.0.0",
44-
"unist-util-visit": "^2.0.0",
45-
"zwitch": "^1.0.0"
49+
"property-information": "^6.0.0",
50+
"space-separated-tokens": "^2.0.0",
51+
"unist-util-visit": "^3.0.0",
52+
"zwitch": "^2.0.0"
4653
},
47-
"files": [
48-
"lib",
49-
"index.js"
50-
],
5154
"devDependencies": {
52-
"browserify": "^17.0.0",
53-
"hastscript": "^6.0.0",
54-
"nyc": "^15.0.0",
55+
"c8": "^7.0.0",
56+
"hastscript": "^7.0.0",
5557
"prettier": "^2.0.0",
5658
"remark-cli": "^9.0.0",
5759
"remark-preset-wooorm": "^8.0.0",
5860
"tape": "^5.0.0",
59-
"tinyify": "^3.0.0",
60-
"unist-builder": "^2.0.0",
61-
"xo": "^0.38.0"
61+
"unist-builder": "^3.0.0",
62+
"xo": "^0.39.0"
6263
},
6364
"scripts": {
6465
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
65-
"build-bundle": "browserify . -s hastUtilSelect > hast-util-select.js",
66-
"build-mangle": "browserify . -s hastUtilSelect -p tinyify > hast-util-select.min.js",
67-
"build": "npm run build-bundle && npm run build-mangle",
68-
"test-api": "node test",
69-
"test-coverage": "nyc --reporter lcov tape test/index.js",
70-
"test": "npm run format && npm run build && npm run test-coverage"
71-
},
72-
"nyc": {
73-
"check-coverage": true,
74-
"lines": 100,
75-
"functions": 100,
76-
"branches": 100
66+
"test-api": "node test/index.js",
67+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js",
68+
"test": "npm run format && npm run test-coverage"
7769
},
7870
"prettier": {
7971
"tabWidth": 2,
@@ -85,26 +77,12 @@
8577
},
8678
"xo": {
8779
"prettier": true,
88-
"esnext": false,
8980
"rules": {
90-
"eqeqeq": [
91-
"error",
92-
"always",
93-
{
94-
"null": "ignore"
95-
}
96-
],
9781
"max-params": "off",
98-
"no-eq-null": "off",
99-
"unicorn/explicit-length-check": "off",
100-
"unicorn/prefer-includes": "off",
101-
"unicorn/prefer-reflect-apply": "off",
102-
"unicorn/prefer-type-error": "off",
103-
"unicorn/no-array-for-each": "off"
104-
},
105-
"ignores": [
106-
"hast-util-select.js"
107-
]
82+
"unicorn/no-array-for-each": "off",
83+
"no-var": "off",
84+
"prefer-arrow-callback": "off"
85+
}
10886
},
10987
"remarkConfig": {
11088
"plugins": [

‎readme.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ This information is not stored in hast, so selectors like that don’t work.
2222

2323
## Install
2424

25+
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
26+
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
27+
2528
[npm][]:
2629

2730
```sh
@@ -30,7 +33,11 @@ npm install hast-util-select
3033

3134
## API
3235

33-
### `select.matches(selector, node[, space])`
36+
This package exports the following identifiers: `matches`, `select`, and
37+
`selectAll`.
38+
There is no default export.
39+
40+
### `matches(selector, node[, space])`
3441

3542
Check that the given `node` matches `selector`.
3643
Returns boolean, whether the node matches or not.
@@ -43,8 +50,8 @@ This only checks that the given element matches the selector.
4350
##### Use
4451

4552
```js
46-
var h = require('hastscript')
47-
var matches = require('hast-util-select').matches
53+
import {h} from 'hastscript'
54+
import {matches} from 'hast-util-select'
4855

4956
matches('b, i', h('b')) // => true
5057
matches(':any-link', h('a')) // => false
@@ -69,7 +76,7 @@ matches('[lang|=en]', h('a', {lang: 'en-GB'})) // => true
6976

7077
`boolean` — Whether the node matches the selector.
7178

72-
### `select.select(selector, tree[, space])`
79+
### `select(selector, tree[, space])`
7380

7481
Select the first `node` matching `selector` in the given `tree` (could be the
7582
tree itself).
@@ -78,8 +85,8 @@ Searches the [*tree*][tree] in [*preorder*][preorder].
7885
##### Use
7986

8087
```js
81-
var h = require('hastscript')
82-
var select = require('hast-util-select').select
88+
import {h} from 'hastscript'
89+
import {select} from 'hast-util-select'
8390

8491
console.log(
8592
select(
@@ -115,7 +122,7 @@ Yields:
115122

116123
[`Element?`][element] — The found element, if any.
117124

118-
### `select.selectAll(selector, tree[, space])`
125+
### `selectAll(selector, tree[, space])`
119126

120127
Select all nodes matching `selector` in the given `tree` (could include the tree
121128
itself).
@@ -124,8 +131,8 @@ Searches the [*tree*][tree] in [*preorder*][preorder].
124131
##### Use
125132

126133
```js
127-
var h = require('hastscript')
128-
var selectAll = require('hast-util-select').selectAll
134+
import {h} from 'hastscript'
135+
import {selectAll} from 'hast-util-select'
129136

130137
console.log(
131138
selectAll(
@@ -224,13 +231,13 @@ Yields:
224231
* [ ]`[*|attr]` (any namespace attribute)
225232
* [ ]`[|attr]` (no namespace attribute)
226233
* [ ]`[attr=value i]` (attribute case-insensitive)
227-
* [ ]`:has()` (functional pseudo-class).
228-
<small>Relative selectors (`:has(> img)`) are not supported, but scope is
234+
* [ ]`:has()` (functional pseudo-class). <small>Relative
235+
selectors (`:has(> img)`) are not supported, but scope is
229236
(`:has(:scope > img)`) </small>
230-
* [ ]`:nth-child(n of S)` (functional pseudo-class).
231-
<small>Scoping to parents is not supported</small>
232-
* [ ]`:nth-last-child(n of S)` (scoped to parent S).
233-
<small>Scoping to parents is not supported</small>
237+
* [ ]`:nth-child(n of S)` (functional pseudo-class). <small>Scoping
238+
to parents is not supported</small>
239+
* [ ]`:nth-last-child(n of S)` (scoped to parent S). <small>Scoping
240+
to parents is not supported</small>
234241
* [ ]`:active` (pseudo-class)
235242
* [ ]`:current` (pseudo-class)
236243
* [ ]`:current()` (functional pseudo-class)

‎test/all.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict'
2-
3-
var test = require('tape')
4-
var u = require('unist-builder')
5-
var h = require('hastscript')
6-
var selectAll = require('..').selectAll
1+
import test from 'tape'
2+
import {u} from 'unist-builder'
3+
import {h} from 'hastscript'
4+
import {selectAll} from '../index.js'
75

86
test('all together now', function (t) {
97
t.deepEqual(

‎test/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict'
2-
31
/* eslint-disable import/no-unassigned-import */
4-
require('./matches')
5-
require('./select')
6-
require('./select-all')
7-
require('./all')
8-
require('./svg')
2+
import './matches.js'
3+
import './select.js'
4+
import './select-all.js'
5+
import './all.js'
6+
import './svg.js'
97
/* eslint-enable import/no-unassigned-import */

‎test/matches.js

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
'use strict'
2-
3-
var test = require('tape')
4-
var u = require('unist-builder')
5-
var h = require('hastscript')
6-
var s = require('hastscript/svg')
7-
var matches = require('..').matches
1+
import test from 'tape'
2+
import {u} from 'unist-builder'
3+
import {h, s} from 'hastscript'
4+
import {matches} from '../index.js'
85

96
test('select.matches()', function (t) {
107
t.test('invalid selector', function (t) {
@@ -18,63 +15,63 @@ test('select.matches()', function (t) {
1815

1916
t.throws(
2017
function () {
21-
matches([], h())
18+
matches([], h(''))
2219
},
2320
/Error: Expected `string` as selector, not ``/,
2421
'should throw w/ invalid selector (1)'
2522
)
2623

2724
t.throws(
2825
function () {
29-
matches('@supports (transform-origin: 5% 5%) {}', h())
26+
matches('@supports (transform-origin: 5% 5%) {}', h(''))
3027
},
3128
/Error: Rule expected but "@" found./,
3229
'should throw w/ invalid selector (2)'
3330
)
3431

3532
t.throws(
3633
function () {
37-
matches('[foo%=bar]', h())
34+
matches('[foo%=bar]', h(''))
3835
},
3936
/Error: Expected "=" but "%" found./,
4037
'should throw on invalid attribute operators'
4138
)
4239

4340
t.throws(
4441
function () {
45-
matches(':active', h())
42+
matches(':active', h(''))
4643
},
4744
/Error: Unknown pseudo-selector `active`/,
4845
'should throw on invalid pseudo classes'
4946
)
5047

5148
t.throws(
5249
function () {
53-
matches(':nth-foo(2n+1)', h())
50+
matches(':nth-foo(2n+1)', h(''))
5451
},
5552
/Error: Unknown pseudo-selector `nth-foo`/,
5653
'should throw on invalid pseudo class “functions”'
5754
)
5855

5956
t.throws(
6057
function () {
61-
matches('::before', h())
58+
matches('::before', h(''))
6259
},
6360
/Error: Unexpected pseudo-element or empty pseudo-class/,
6461
'should throw on invalid pseudo elements'
6562
)
6663

6764
t.throws(
6865
function () {
69-
matches('foo bar', h())
66+
matches('foo bar', h(''))
7067
},
7168
/Error: Expected selector without nesting/,
7269
'should throw on nested selectors (descendant)'
7370
)
7471

7572
t.throws(
7673
function () {
77-
matches('foo > bar', h())
74+
matches('foo > bar', h(''))
7875
},
7976
/Error: Expected selector without nesting/,
8077
'should throw on nested selectors (direct child)'
@@ -103,7 +100,7 @@ test('select.matches()', function (t) {
103100
simplePseudos.forEach(function (pseudo) {
104101
t.throws(
105102
function () {
106-
matches(':' + pseudo, h())
103+
matches(':' + pseudo, h(''))
107104
},
108105
new RegExp('Error: Cannot use `:' + pseudo + '` without parent'),
109106
'should throw on `' + pseudo + '`'
@@ -113,7 +110,7 @@ test('select.matches()', function (t) {
113110
functionalPseudos.forEach(function (pseudo) {
114111
t.throws(
115112
function () {
116-
matches(':' + pseudo + '()', h())
113+
matches(':' + pseudo + '()', h(''))
117114
},
118115
new RegExp('Error: Cannot use `:' + pseudo + '` without parent'),
119116
'should throw on `' + pseudo + '()`'
@@ -124,8 +121,8 @@ test('select.matches()', function (t) {
124121
})
125122

126123
t.test('general', function (t) {
127-
t.notOk(matches('', h()), 'false for the empty string as selector')
128-
t.notOk(matches(' ', h()), 'false for a white-space only selector')
124+
t.notOk(matches('', h('')), 'false for the empty string as selector')
125+
t.notOk(matches(' ', h('')), 'false for a white-space only selector')
129126
t.notOk(matches('*'), 'false if not given a node')
130127
t.notOk(
131128
matches('*', {type: 'text', value: 'a'}),
@@ -143,15 +140,15 @@ test('select.matches()', function (t) {
143140
})
144141

145142
t.test('tag-names: `div`, `*`', function (t) {
146-
t.ok(matches('*', h()), 'true for `*`')
143+
t.ok(matches('*', h('')), 'true for `*`')
147144
t.ok(matches('b', h('b')), 'true if tag-names matches')
148145
t.notOk(matches('b', h('i')), 'false if tag-names don’t matches')
149146

150147
t.end()
151148
})
152149

153150
t.test('id: `#id`', function (t) {
154-
t.notOk(matches('#one', h()), 'false if no id exists')
151+
t.notOk(matches('#one', h('')), 'false if no id exists')
155152
t.ok(matches('#one', h('#one')), 'true for matchesing id’s')
156153
t.notOk(matches('#two', h('#one')), 'false for mismatchesed id’s')
157154
t.ok(
@@ -167,7 +164,7 @@ test('select.matches()', function (t) {
167164
})
168165

169166
t.test('class: `.class`', function (t) {
170-
t.notOk(matches('.one', h()), 'false if no class-name exists')
167+
t.notOk(matches('.one', h('')), 'false if no class-name exists')
171168
t.ok(matches('.one', h('.one')), 'true for matchesing class-name')
172169
t.ok(
173170
matches('.one', h('.one.two')),
@@ -932,7 +929,7 @@ test('select.matches()', function (t) {
932929
'false for options w/o `selected`'
933930
)
934931

935-
t.notOk(matches(':checked', h()), 'false for other nodes')
932+
t.notOk(matches(':checked', h('')), 'false for other nodes')
936933

937934
t.end()
938935
})
@@ -1010,33 +1007,33 @@ test('select.matches()', function (t) {
10101007
})
10111008

10121009
t.test(':empty', function (t) {
1013-
t.ok(matches(':empty', h()), 'true if w/o children')
1010+
t.ok(matches(':empty', h('')), 'true if w/o children')
10141011
t.ok(
1015-
matches(':empty', h(null, u('comment', '?'))),
1012+
matches(':empty', h('', u('comment', '?'))),
10161013
'true if w/o elements or texts'
10171014
)
1018-
t.notOk(matches(':empty', h(null, h())), 'false if w/ elements')
1019-
t.notOk(matches(':empty', h(null, u('text', '.'))), 'false if w/ text')
1015+
t.notOk(matches(':empty', h('', h(''))), 'false if w/ elements')
1016+
t.notOk(matches(':empty', h('', u('text', '.'))), 'false if w/ text')
10201017
t.notOk(
1021-
matches(':empty', h(null, u('text', ' '))),
1018+
matches(':empty', h('', u('text', ' '))),
10221019
'false if w/ white-space text'
10231020
)
10241021

10251022
t.end()
10261023
})
10271024

10281025
t.test(':blank', function (t) {
1029-
t.ok(matches(':blank', h()), 'true if w/o children')
1026+
t.ok(matches(':blank', h('')), 'true if w/o children')
10301027
t.ok(
1031-
matches(':blank', h(null, u('comment', '?'))),
1028+
matches(':blank', h('', u('comment', '?'))),
10321029
'true if w/o elements or texts'
10331030
)
10341031
t.ok(
1035-
matches(':blank', h(null, u('text', ' '))),
1032+
matches(':blank', h('', u('text', ' '))),
10361033
'true if w/ white-space text'
10371034
)
1038-
t.notOk(matches(':blank', h(null, h())), 'false if w/ elements')
1039-
t.notOk(matches(':blank', h(null, u('text', '.'))), 'false if w/ text')
1035+
t.notOk(matches(':blank', h('', h(''))), 'false if w/ elements')
1036+
t.notOk(matches(':blank', h('', u('text', '.'))), 'false if w/ text')
10401037

10411038
t.end()
10421039
})

‎test/select-all.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
'use strict'
2-
3-
var test = require('tape')
4-
var u = require('unist-builder')
5-
var s = require('hastscript/svg')
6-
var h = require('hastscript')
7-
var selectAll = require('..').selectAll
1+
import test from 'tape'
2+
import {u} from 'unist-builder'
3+
import {h, s} from 'hastscript'
4+
import {selectAll} from '../index.js'
85

96
test('select.selectAll()', function (t) {
107
t.test('invalid selectors', function (t) {
@@ -18,47 +15,47 @@ test('select.selectAll()', function (t) {
1815

1916
t.throws(
2017
function () {
21-
selectAll([], h())
18+
selectAll([], h(''))
2219
},
2320
/Error: Expected `string` as selector, not ``/,
2421
'should throw w/ invalid selector (1)'
2522
)
2623

2724
t.throws(
2825
function () {
29-
selectAll('@supports (transform-origin: 5% 5%) {}', h())
26+
selectAll('@supports (transform-origin: 5% 5%) {}', h(''))
3027
},
3128
/Error: Rule expected but "@" found./,
3229
'should throw w/ invalid selector (2)'
3330
)
3431

3532
t.throws(
3633
function () {
37-
selectAll('[foo%=bar]', h())
34+
selectAll('[foo%=bar]', h(''))
3835
},
3936
/Error: Expected "=" but "%" found./,
4037
'should throw on invalid attribute operators'
4138
)
4239

4340
t.throws(
4441
function () {
45-
selectAll(':active', h())
42+
selectAll(':active', h(''))
4643
},
4744
/Error: Unknown pseudo-selector `active`/,
4845
'should throw on invalid pseudo classes'
4946
)
5047

5148
t.throws(
5249
function () {
53-
selectAll(':nth-foo(2n+1)', h())
50+
selectAll(':nth-foo(2n+1)', h(''))
5451
},
5552
/Error: Unknown pseudo-selector `nth-foo`/,
5653
'should throw on invalid pseudo class “functions”'
5754
)
5855

5956
t.throws(
6057
function () {
61-
selectAll('::before', h())
58+
selectAll('::before', h(''))
6259
},
6360
/Error: Unexpected pseudo-element or empty pseudo-class/,
6461
'should throw on invalid pseudo elements'
@@ -69,12 +66,12 @@ test('select.selectAll()', function (t) {
6966

7067
t.test('general', function (t) {
7168
t.deepEqual(
72-
selectAll('', h()),
69+
selectAll('', h('')),
7370
[],
7471
'nothing for the empty string as selector'
7572
)
7673
t.deepEqual(
77-
selectAll(' ', h()),
74+
selectAll(' ', h('')),
7875
[],
7976
'nothing for a white-space only selector'
8077
)

‎test/select.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
'use strict'
2-
3-
var test = require('tape')
4-
var u = require('unist-builder')
5-
var s = require('hastscript/svg')
6-
var h = require('hastscript')
7-
var select = require('..').select
1+
import test from 'tape'
2+
import {u} from 'unist-builder'
3+
import {h, s} from 'hastscript'
4+
import {select} from '../index.js'
85

96
test('select.select()', function (t) {
107
t.test('invalid selectors', function (t) {
@@ -18,47 +15,47 @@ test('select.select()', function (t) {
1815

1916
t.throws(
2017
function () {
21-
select([], h())
18+
select([], h(''))
2219
},
2320
/Error: Expected `string` as selector, not ``/,
2421
'should throw w/ invalid selector (1)'
2522
)
2623

2724
t.throws(
2825
function () {
29-
select('@supports (transform-origin: 5% 5%) {}', h())
26+
select('@supports (transform-origin: 5% 5%) {}', h(''))
3027
},
3128
/Error: Rule expected but "@" found./,
3229
'should throw w/ invalid selector (2)'
3330
)
3431

3532
t.throws(
3633
function () {
37-
select('[foo%=bar]', h())
34+
select('[foo%=bar]', h(''))
3835
},
3936
/Error: Expected "=" but "%" found./,
4037
'should throw on invalid attribute operators'
4138
)
4239

4340
t.throws(
4441
function () {
45-
select(':active', h())
42+
select(':active', h(''))
4643
},
4744
/Error: Unknown pseudo-selector `active`/,
4845
'should throw on invalid pseudo classes'
4946
)
5047

5148
t.throws(
5249
function () {
53-
select(':nth-foo(2n+1)', h())
50+
select(':nth-foo(2n+1)', h(''))
5451
},
5552
/Error: Unknown pseudo-selector `nth-foo`/,
5653
'should throw on invalid pseudo class “functions”'
5754
)
5855

5956
t.throws(
6057
function () {
61-
select('::before', h())
58+
select('::before', h(''))
6259
},
6360
/Error: Unexpected pseudo-element or empty pseudo-class/,
6461
'should throw on invalid pseudo elements'
@@ -68,8 +65,8 @@ test('select.select()', function (t) {
6865
})
6966

7067
t.test('general', function (t) {
71-
t.equal(select('', h()), null, 'nothing for the empty string as selector')
72-
t.equal(select(' ', h()), null, 'nothing for a white-space only selector')
68+
t.equal(select('', h('')), null, 'nothing for the empty string as selector')
69+
t.equal(select(' ', h('')), null, 'nothing for a white-space only selector')
7370
t.equal(select('*'), null, 'nothing if not given a node')
7471
t.equal(
7572
select('*', {type: 'text', value: 'a'}),

‎test/svg.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
'use strict'
2-
3-
var test = require('tape')
4-
var u = require('unist-builder')
5-
var s = require('hastscript/svg')
6-
var h = require('hastscript')
7-
var select = require('..').select
8-
var selectAll = require('..').selectAll
1+
import test from 'tape'
2+
import {u} from 'unist-builder'
3+
import {h, s} from 'hastscript'
4+
import {select, selectAll} from '../index.js'
95

106
test('svg', function (t) {
117
t.deepEqual(

0 commit comments

Comments
 (0)
Please sign in to comment.