Skip to content

Commit e1e821c

Browse files
committed
Change to never match multiple ids
This matches CSS.
1 parent 3592016 commit e1e821c

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

lib/id.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {ok as assert} from 'devlop'
1717
* Whether `element` matches `query`.
1818
*/
1919
export function id(query, element) {
20-
assert(query.ids, 'expected `ids`')
21-
const id = query.ids[query.ids.length - 1]
22-
return Boolean(element.properties.id === id)
20+
const ids = query.ids
21+
assert(ids, 'expected `ids`')
22+
return ids.length === 1 && element.properties.id === ids[0]
2323
}

test/matches.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,13 @@ test('select.matches()', async function (t) {
183183
assert.ok(!matches('#two', h('#one')))
184184
})
185185

186-
await t.test(
187-
'should prefer the last id if multiple id’s are specified (1)',
188-
async function () {
189-
assert.ok(matches('#two#one', h('#one')))
190-
}
191-
)
186+
await t.test('should never match multiple ids (#1)', async function () {
187+
assert.ok(!matches('#a#x', h('#a')))
188+
})
192189

193-
await t.test(
194-
'should prefer the last id if multiple id’s are specified (2)',
195-
async function () {
196-
assert.ok(!matches('#one#two', h('#one')))
197-
}
198-
)
190+
await t.test('should never match multiple ids (#2)', async function () {
191+
assert.ok(!matches('#a#x', h('#x')))
192+
})
199193
})
200194

201195
await t.test('class: `.class`', async function (t) {

0 commit comments

Comments
 (0)