Skip to content

Commit

Permalink
Refactor error for unsupported feature
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 6, 2023
1 parent 1075824 commit 5c37078
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/pseudo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @typedef {import('./types.js').SelectState} SelectState
*/

import {unreachable} from 'devlop'
import {ok as assert, unreachable} from 'devlop'
import fauxEsmNthCheck from 'nth-check'
import {zwitch} from 'zwitch'
import {parent} from './util.js'
Expand Down Expand Up @@ -409,10 +409,12 @@ function getCachedNthCheck(query) {

if (!fn) {
const value = query.argument
assert(value, 'expected `argument`')

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

fn = nthCheck(value.a + 'n+' + value.b)
Expand Down
9 changes: 9 additions & 0 deletions test/select-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,15 @@ test('select.selectAll()', async function (t) {
[u('b', 'Bravo'), u('b', 'Delta'), u('b', 'Foxtrot')]
)
})

await t.test(
'should throw on unsupported `of` syntax',
async function () {
assert.throws(function () {
selectAll(':nth-child(odd of a)', u('a'))
}, /Expected `nth` formula, such as `even` or `2n\+1` \(`of` is not yet supported\)/)
}
)
})

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

0 comments on commit 5c37078

Please sign in to comment.