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
14 changes: 8 additions & 6 deletions src/core/calculate.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ const calculateSpecificityOfSelectorObject = (selectorObj) => {
case 'any':
case 'not':
case 'has':
// Calculate Specificity from nested SelectorList
const max1 = max(...calculate(child.children.first));
if (child.children) {
// Calculate Specificity from nested SelectorList
const max1 = max(...calculate(child.children.first));

// Adjust orig specificity
specificity.a += max1.a;
specificity.b += max1.b;
specificity.c += max1.c;
// Adjust orig specificity
specificity.a += max1.a;
specificity.b += max1.b;
specificity.c += max1.c;
}

break;

Expand Down
15 changes: 15 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ describe('CALCULATE', () => {
});
});

describe('CSS empty :is, :matches, :any, :where = (0,0,0)', () => {
it(':is = (0,0,0)', () => {
deepEqual(Specificity.calculate(':is')[0].toObject(), { a: 0, b: 0, c: 0 });
});
it(':matches = (0,0,0)', () => {
deepEqual(Specificity.calculate(':matches')[0].toObject(), { a: 0, b: 0, c: 0 });
});
it(':any = (0,0,0)', () => {
deepEqual(Specificity.calculate(':any')[0].toObject(), { a: 0, b: 0, c: 0 });
});
it(':where = (0,0,0)', () => {
deepEqual(Specificity.calculate(':where')[0].toObject(), { a: 0, b: 0, c: 0 });
});
});

describe('CSS :has() = Specificity of the most specific complex selector in its selector list argument', () => {
it(':has(#foo, .bar, baz) = (1,0,0)', () => {
deepEqual(Specificity.calculate(':has(#foo, .bar, baz)')[0].toObject(), { a: 1, b: 0, c: 0 });
Expand Down