Skip to content

Commit 1da3f61

Browse files
committed
Fix types to allow literal nodes
1 parent 40941a9 commit 1da3f61

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
/**
2+
* @typedef {import('unist').Position} Position
23
* @typedef {import('unist').Node} Node
4+
* @typedef {Record<string, unknown> & {type: string, position?: Position|undefined}} NodeLike
35
*/
46

57
import {any} from './lib/any.js'
68
import {parse} from './lib/parse.js'
79

810
/**
911
* @param {string} selector
10-
* @param {Node} [node]
12+
* @param {NodeLike|Node} [node]
1113
* @returns {boolean}
1214
*/
1315
export function matches(selector, node) {
@@ -16,7 +18,7 @@ export function matches(selector, node) {
1618

1719
/**
1820
* @param {string} selector
19-
* @param {Node} [node]
21+
* @param {NodeLike|Node} [node]
2022
* @returns {Node|null}
2123
*/
2224
export function select(selector, node) {
@@ -25,8 +27,8 @@ export function select(selector, node) {
2527

2628
/**
2729
* @param {string} selector
28-
* @param {Node} [node]
29-
* @returns {Array.<Node>}
30+
* @param {NodeLike|Node} [node]
31+
* @returns {Array<Node>}
3032
*/
3133
export function selectAll(selector, node) {
3234
return any(parse(selector), node, {any})

test/matches.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import {u} from 'unist-builder'
77
import {matches} from '../index.js'
88

99
test('select.matches()', (t) => {
10+
t.equal(matches('*', u('root', [])), true, 'should work (1)')
11+
t.equal(matches('*', {type: 'a', children: []}), true, 'should work (2)')
12+
1013
t.test('invalid selector', (st) => {
1114
st.throws(
1215
() => {

0 commit comments

Comments
 (0)