Skip to content

Commit 5c37078

Browse files
committed
Refactor error for unsupported feature
1 parent 1075824 commit 5c37078

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/pseudo.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @typedef {import('./types.js').SelectState} SelectState
77
*/
88

9-
import {unreachable} from 'devlop'
9+
import {ok as assert, unreachable} from 'devlop'
1010
import fauxEsmNthCheck from 'nth-check'
1111
import {zwitch} from 'zwitch'
1212
import {parent} from './util.js'
@@ -409,10 +409,12 @@ function getCachedNthCheck(query) {
409409

410410
if (!fn) {
411411
const value = query.argument
412+
assert(value, 'expected `argument`')
412413

413-
/* c8 ignore next 3 -- never happens with our config */
414-
if (!value || value.type !== 'Formula') {
415-
unreachable('`:nth` has a formula')
414+
if (value.type !== 'Formula') {
415+
throw new Error(
416+
'Expected `nth` formula, such as `even` or `2n+1` (`of` is not yet supported)'
417+
)
416418
}
417419

418420
fn = nthCheck(value.a + 'n+' + value.b)

test/select-all.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,15 @@ test('select.selectAll()', async function (t) {
438438
[u('b', 'Bravo'), u('b', 'Delta'), u('b', 'Foxtrot')]
439439
)
440440
})
441+
442+
await t.test(
443+
'should throw on unsupported `of` syntax',
444+
async function () {
445+
assert.throws(function () {
446+
selectAll(':nth-child(odd of a)', u('a'))
447+
}, /Expected `nth` formula, such as `even` or `2n\+1` \(`of` is not yet supported\)/)
448+
}
449+
)
441450
})
442451

443452
await t.test(':nth-last-child', async function (t) {

0 commit comments

Comments
 (0)