Skip to content

Commit

Permalink
Fix calculation of any pseudo class (#22)
Browse files Browse the repository at this point in the history
* Fix calculation of any pseudo class

* Correct -moz-any() specificity calculation
  • Loading branch information
carlosjeurissen committed Feb 18, 2024
1 parent 771a237 commit 97ccbaf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/core/calculate.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ const calculateSpecificityOfSelectorObject = (selectorObj) => {
// Noop :)
break;

case '-webkit-any':
case 'any':
if (child.children) {
specificity.b += 1;
}
break;

// “The specificity of an :is(), :not(), or :has() pseudo-class is replaced by the specificity of the most specific complex selector in its selector list argument.“
case '-moz-any':
case 'is':
case 'matches':
case '-webkit-any':
case '-moz-any':
case 'any':
case 'not':
case 'has':
if (child.children) {
Expand Down
15 changes: 9 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,24 @@ describe('CALCULATE', () => {
});
});

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

describe('CSS :any() = (0,1,0)', () => {
it(':any(#foo, .bar, baz) = (0,1,0)', () => {
deepEqual(Specificity.calculate(':any(#foo, .bar, baz)')[0].toObject(), { a: 0, b: 1, c: 0 });
});
it(':-webkit-any(#foo, .bar, baz) = (0,1,0)', () => {
deepEqual(Specificity.calculate(':-webkit-any(#foo, .bar, baz)')[0].toObject(), { a: 0, b: 1, c: 0 });
});
});

Expand Down

0 comments on commit 97ccbaf

Please sign in to comment.