Skip to content

Commit 414d1f7

Browse files
committed
Change to yield undefined instead of null
1 parent a54914e commit 414d1f7

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function matches(selector, node) {
4444
* CSS selector, such as (`heading`, `link, linkReference`).
4545
* @param {Node | NodeLike | null | undefined} [tree]
4646
* Tree to search.
47-
* @returns {Node | null}
47+
* @returns {Node | undefined}
4848
* First node in `tree` that matches `selector` or `null` if nothing is
4949
* found.
5050
*
@@ -54,8 +54,7 @@ export function select(selector, tree) {
5454
const state = createState(selector, tree)
5555
state.one = true
5656
walk(state, tree || undefined)
57-
// To do next major: return `undefined`.
58-
return state.results[0] || null
57+
return state.results[0]
5958
}
6059

6160
/**

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ Searches the tree in *[preorder][]*.
150150

151151
###### Returns
152152

153-
First node in `tree` that matches `selector` or `null` if nothing is found.
153+
First node in `tree` that matches `selector` or `undefined` if nothing is found.
154154

155155
This could be `tree` itself.
156156

test/select.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ test('select.select()', async function (t) {
7676
)
7777

7878
await t.test('should yield nothing if not given a node', async function () {
79-
assert.equal(select('*'), null)
79+
assert.equal(select('*'), undefined)
8080
})
8181

8282
await t.test('should yield the node if given a node', async function () {
@@ -184,7 +184,7 @@ test('select.select()', async function (t) {
184184
u('b', 'Delta')
185185
])
186186
),
187-
null
187+
undefined
188188
)
189189
})
190190
})
@@ -227,7 +227,7 @@ test('select.select()', async function (t) {
227227
'c ~ b',
228228
u('a', [u('b', 'Alpha'), u('c', 'Bravo'), u('d', 'Charlie')])
229229
),
230-
null
230+
undefined
231231
)
232232
})
233233
})
@@ -258,7 +258,7 @@ test('select.select()', async function (t) {
258258
'c:first-child',
259259
u('a', [u('b', 'Alpha'), u('c', 'Bravo'), u('d', 'Charlie')])
260260
),
261-
null
261+
undefined
262262
)
263263
}
264264
)
@@ -289,7 +289,7 @@ test('select.select()', async function (t) {
289289
'c:last-child',
290290
u('a', [u('b', 'Alpha'), u('c', 'Bravo'), u('d', 'Charlie')])
291291
),
292-
null
292+
undefined
293293
)
294294
}
295295
)
@@ -320,7 +320,7 @@ test('select.select()', async function (t) {
320320
'c:only-child',
321321
u('a', [u('b', 'Alpha'), u('c', 'Bravo'), u('d', 'Charlie')])
322322
),
323-
null
323+
undefined
324324
)
325325
}
326326
)
@@ -676,7 +676,7 @@ test('select.select()', async function (t) {
676676
)
677677

678678
await t.test('should return nothing without matches', async function () {
679-
assert.equal(select('b:first-of-type', u('a', [])), null)
679+
assert.equal(select('b:first-of-type', u('a', [])), undefined)
680680
})
681681
})
682682

@@ -702,7 +702,7 @@ test('select.select()', async function (t) {
702702
)
703703

704704
await t.test('should return nothing without matches', async function () {
705-
assert.equal(select('b:last-of-type', u('a', [])), null)
705+
assert.equal(select('b:last-of-type', u('a', [])), undefined)
706706
})
707707
})
708708

@@ -737,13 +737,13 @@ test('select.select()', async function (t) {
737737
u('c', 'Foxtrot')
738738
])
739739
),
740-
null
740+
undefined
741741
)
742742
}
743743
)
744744

745745
await t.test('should return nothing without matches', async function () {
746-
assert.equal(select('b:only-of-type', u('a', [])), null)
746+
assert.equal(select('b:only-of-type', u('a', [])), undefined)
747747
})
748748
})
749749

0 commit comments

Comments
 (0)