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
2 changes: 1 addition & 1 deletion src/core/calculate.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const calculateSpecificityOfSelectorObject = (selectorObj) => {
case 'nth-last-child':
specificity.b += 1;

if (child.children.first.selector) {
if (child.children && child.children.first.selector) {
// Calculate Specificity from SelectorList
const max2 = max(...calculate(child.children.first.selector));

Expand Down
9 changes: 9 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ describe('CALCULATE', () => {
it(':focus', () => {
deepEqual(Specificity.calculate(':focus')[0].toObject(), { a: 0, b: 1, c: 0 });
});
it('p:nth-child(1) = (0,1,1)', () => {
deepEqual(Specificity.calculate('p:nth-child(1)')[0].toObject(), { a: 0, b: 1, c: 1 });
});
it('p:nth-child(2n+1) = (0,1,1)', () => {
deepEqual(Specificity.calculate('p:nth-child(2n+1)')[0].toObject(), { a: 0, b: 1, c: 1 });
});
it('p:nth-child = (0,1,1) & do not crash', () => {
deepEqual(Specificity.calculate('p:nth-child')[0].toObject(), { a: 0, b: 1, c: 1 });
});
});

describe('CSS :is(), :matches(), :-moz-any = Specificity of the most specific complex selector in its selector list argument', () => {
Expand Down