diff --git a/src/core/calculate.js b/src/core/calculate.js index f05b1ae..70510e5 100644 --- a/src/core/calculate.js +++ b/src/core/calculate.js @@ -161,6 +161,18 @@ const calculateForAST = (selectorAST) => { c += 1; break; + case 'highlight': + if (child.children?.size > 0) { + // The specificity of a ::highlight() selector with a * argument is zero. + if (child.children.first?.value === '*') { + break; + } + // The specificity of a ::highlight() selector with a argument + // is equivalent to a type selector. + c += 1; + } + break; + default: c += 1; break; diff --git a/test/index.js b/test/index.js index 6d32d1f..57ec6bb 100644 --- a/test/index.js +++ b/test/index.js @@ -77,6 +77,24 @@ describe('CALCULATE', () => { it('::first-letter', () => { deepEqual(Specificity.calculate('::first-letter')[0].toObject(), { a: 0, b: 0, c: 1 }); }); + it('::part(my-ident)', () => { + deepEqual(Specificity.calculate('::part(my-ident)')[0].toObject(), { a: 0, b: 0, c: 1 }); + }); + it('::part(first-ident second-ident)', () => { + deepEqual(Specificity.calculate('::part(first-ident second-ident)')[0].toObject(), { a: 0, b: 0, c: 1 }); + }); + it('::highlight & do not crash', () => { + deepEqual(Specificity.calculate('::highlight')[0].toObject(), { a: 0, b: 0, c: 0 }); + }); + it('::highlight() & do not crash', () => { + deepEqual(Specificity.calculate('::highlight')[0].toObject(), { a: 0, b: 0, c: 0 }); + }); + it('::highlight(my-ident)', () => { + deepEqual(Specificity.calculate('::highlight(my-ident)')[0].toObject(), { a: 0, b: 0, c: 1 }); + }); + it('::highlight(*)', () => { + deepEqual(Specificity.calculate('::highlight(*)')[0].toObject(), { a: 0, b: 0, c: 0 }); + }); }); describe('Pseudo-Element Selector ::slotted', () => {