Skip to content

Commit db5ea46

Browse files
committed
Change to yield undefined
1 parent 87996c8 commit db5ea46

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

lib/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,15 @@ export function matches(selector, node, space) {
8787
* Tree to search (optional).
8888
* @param {Space | null | undefined} [space='html']
8989
* Name of namespace (default: `'html'`).
90-
* @returns {Element | null}
91-
* First element in `tree` that matches `selector` or `null` if nothing is
92-
* found.
93-
* This could be `tree` itself.
90+
* @returns {Element | undefined}
91+
* First element in `tree` that matches `selector` or `undefined` if nothing
92+
* is found; this could be `tree` itself.
9493
*/
9594
export function select(selector, tree, space) {
9695
const state = createState(selector, tree, space)
9796
state.one = true
9897
walk(state, tree || undefined)
99-
// To do in major: return `undefined` instead.
100-
return state.results[0] || null
98+
return state.results[0]
10199
}
102100

103101
/**

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ Searches the tree in *[preorder][]*.
160160

161161
###### Returns
162162

163-
First element in `tree` that matches `selector` or `null` if nothing is found.
163+
First element in `tree` that matches `selector` or `undefined` if nothing is
164+
found.
164165
This could be `tree` itself.
165166

166167
###### Example

test/select.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ test('select.select()', async function (t) {
7474
)
7575

7676
await t.test('should not select if not given a node', async function () {
77-
assert.equal(select('*'), null)
77+
assert.equal(select('*'), undefined)
7878
})
7979

8080
await t.test(
8181
'should not select if not given an element',
8282
async function () {
83-
assert.equal(select('*', {type: 'text', value: 'a'}), null)
83+
assert.equal(select('*', {type: 'text', value: 'a'}), undefined)
8484
}
8585
)
8686

@@ -219,7 +219,7 @@ test('select.select()', async function (t) {
219219
h('p', 'Delta')
220220
])
221221
),
222-
null
222+
undefined
223223
)
224224
})
225225
})
@@ -290,7 +290,7 @@ test('select.select()', async function (t) {
290290
'h1 ~ p',
291291
u('root', [h('p', 'Alpha'), h('h1', 'Bravo'), h('h2', 'Charlie')])
292292
),
293-
null
293+
undefined
294294
)
295295
})
296296
})
@@ -321,7 +321,7 @@ test('select.select()', async function (t) {
321321
'h1:first-child',
322322
u('root', [h('p', 'Alpha'), h('h1', 'Bravo'), h('p', 'Charlie')])
323323
),
324-
null
324+
undefined
325325
)
326326
}
327327
)
@@ -352,7 +352,7 @@ test('select.select()', async function (t) {
352352
'h1:last-child',
353353
u('root', [h('p', 'Alpha'), h('h1', 'Bravo'), h('p', 'Charlie')])
354354
),
355-
null
355+
undefined
356356
)
357357
}
358358
)
@@ -383,7 +383,7 @@ test('select.select()', async function (t) {
383383
'h1:only-child',
384384
u('root', [h('p', 'Alpha'), h('h1', 'Bravo'), h('p', 'Charlie')])
385385
),
386-
null
386+
undefined
387387
)
388388
}
389389
)
@@ -739,7 +739,7 @@ test('select.select()', async function (t) {
739739
)
740740

741741
await t.test('should return nothing without matches', async function () {
742-
assert.equal(select('dt:first-of-type', h('dl', [])), null)
742+
assert.equal(select('dt:first-of-type', h('dl', [])), undefined)
743743
})
744744
})
745745

@@ -765,7 +765,7 @@ test('select.select()', async function (t) {
765765
)
766766

767767
await t.test('should return nothing without matches', async function () {
768-
assert.equal(select('dt:last-of-type', h('dl', [])), null)
768+
assert.equal(select('dt:last-of-type', h('dl', [])), undefined)
769769
})
770770
})
771771

@@ -800,13 +800,13 @@ test('select.select()', async function (t) {
800800
h('dd', 'Foxtrot')
801801
])
802802
),
803-
null
803+
undefined
804804
)
805805
}
806806
)
807807

808808
await t.test('should return nothing without matches', async function () {
809-
assert.equal(select('dt:only-of-type', h('dl', [])), null)
809+
assert.equal(select('dt:only-of-type', h('dl', [])), undefined)
810810
})
811811
})
812812
})
@@ -885,7 +885,7 @@ test('select.select()', async function (t) {
885885
])
886886
])
887887
),
888-
null
888+
undefined
889889
)
890890
}
891891
)
@@ -900,7 +900,7 @@ test('select.select()', async function (t) {
900900
'p:read-only',
901901
u('root', [h('div', {contentEditable: 'true'}, [h('p', 'A')])])
902902
),
903-
null
903+
undefined
904904
)
905905
}
906906
)

test/svg.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ test('svg', async function (t) {
4646
await t.test('should match svg (#3)', async function () {
4747
assert.deepEqual(
4848
select('[writing-mode]', s('text', {writingMode: 'lr-tb'}, '!')),
49-
null
49+
undefined
5050
)
5151
})
5252

0 commit comments

Comments
 (0)