Last change
on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | module.exports = function specificity(simpleSelector) {
|
---|
| 2 | var A = 0;
|
---|
| 3 | var B = 0;
|
---|
| 4 | var C = 0;
|
---|
| 5 |
|
---|
| 6 | simpleSelector.children.each(function walk(node) {
|
---|
| 7 | switch (node.type) {
|
---|
| 8 | case 'SelectorList':
|
---|
| 9 | case 'Selector':
|
---|
| 10 | node.children.each(walk);
|
---|
| 11 | break;
|
---|
| 12 |
|
---|
| 13 | case 'IdSelector':
|
---|
| 14 | A++;
|
---|
| 15 | break;
|
---|
| 16 |
|
---|
| 17 | case 'ClassSelector':
|
---|
| 18 | case 'AttributeSelector':
|
---|
| 19 | B++;
|
---|
| 20 | break;
|
---|
| 21 |
|
---|
| 22 | case 'PseudoClassSelector':
|
---|
| 23 | switch (node.name.toLowerCase()) {
|
---|
| 24 | case 'not':
|
---|
| 25 | node.children.each(walk);
|
---|
| 26 | break;
|
---|
| 27 |
|
---|
| 28 | case 'before':
|
---|
| 29 | case 'after':
|
---|
| 30 | case 'first-line':
|
---|
| 31 | case 'first-letter':
|
---|
| 32 | C++;
|
---|
| 33 | break;
|
---|
| 34 |
|
---|
| 35 | // TODO: support for :nth-*(.. of <SelectorList>), :matches(), :has()
|
---|
| 36 | default:
|
---|
| 37 | B++;
|
---|
| 38 | }
|
---|
| 39 | break;
|
---|
| 40 |
|
---|
| 41 | case 'PseudoElementSelector':
|
---|
| 42 | C++;
|
---|
| 43 | break;
|
---|
| 44 |
|
---|
| 45 | case 'TypeSelector':
|
---|
| 46 | // ignore universal selector
|
---|
| 47 | if (node.name.charAt(node.name.length - 1) !== '*') {
|
---|
| 48 | C++;
|
---|
| 49 | }
|
---|
| 50 | break;
|
---|
| 51 |
|
---|
| 52 | }
|
---|
| 53 | });
|
---|
| 54 |
|
---|
| 55 | return [A, B, C];
|
---|
| 56 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.