Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/selectors/specificity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,38 @@ test('handles pseudo element selectors', () => {
expect(actual).toEqual(expected)
})

test('handles the ::part pseudo element', () => {
const fixture = `
::part(my-ident),
::part(first-ident second-ident)
{}
`
const actual = analyze(fixture).selectors.specificity.items
const expected = [
[0, 0, 1],
[0, 0, 1],
]
expect(actual).toEqual(expected)
})

test('handles the ::highlight pseudo element', () => {
const fixture = `
::highlight,
::highlight(),
::highlight(my-ident),
::highlight(*)
{}
`
const actual = analyze(fixture).selectors.specificity.items
const expected = [
[0, 0, 0],
[0, 0, 0],
[0, 0, 1],
[0, 0, 0],
]
expect(actual).toEqual(expected)
})

test('calculates the lowest value', () => {
const fixture = `
#test,
Expand Down
13 changes: 13 additions & 0 deletions src/selectors/specificity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ export const calculateForAST = (selectorAST: Selector): Specificity => {
break
}

case 'highlight': {
if (current.first_child) {
// The specificity of a ::highlight() selector with a * argument is zero.
if (current.first_child.text === '*') {
break
}
// The specificity of a ::highlight() selector with a <custom-ident> argument
// is equivalent to a type selector.
c += 1
}
break
}

default: {
c += 1
break
Expand Down
Loading