UNPKG

1.55 kBJavaScriptView Raw
1'use strict';
2
3const keywordSets = require('../reference/keywordSets');
4
5/**
6 * Check whether a type selector is standard
7 *
8 * @param {import('postcss-selector-parser').Tag} node postcss-selector-parser node (of type tag)
9 * @return {boolean} If `true`, the type selector is standard
10 */
11module.exports = function (node) {
12 // postcss-selector-parser includes the arguments to nth-child() functions
13 // as "tags", so we need to ignore them ourselves.
14 // The fake-tag's "parent" is actually a selector node, whose parent
15 // should be the :nth-child pseudo node.
16 if (!node.parent || !node.parent.parent) {
17 return false;
18 }
19
20 const _node$parent$parent = node.parent.parent;
21 const parentType = _node$parent$parent.type;
22 const parentValue = _node$parent$parent.value;
23
24 if (parentValue) {
25 const normalisedParentName = parentValue.toLowerCase().replace(/:+/, '');
26
27 if (
28 parentType === 'pseudo' &&
29 (keywordSets.aNPlusBNotationPseudoClasses.has(normalisedParentName) ||
30 keywordSets.aNPlusBOfSNotationPseudoClasses.has(normalisedParentName) ||
31 keywordSets.linguisticPseudoClasses.has(normalisedParentName) ||
32 keywordSets.shadowTreePseudoElements.has(normalisedParentName))
33 ) {
34 return false;
35 }
36 }
37
38 // &-bar is a nesting selector combined with a suffix
39 if (node.prev() && node.prev().type === 'nesting') {
40 return false;
41 }
42
43 if (node.value.startsWith('%')) {
44 return false;
45 }
46
47 // Reference combinators like `/deep/`
48 if (node.value.startsWith('/') && node.value.endsWith('/')) {
49 return false;
50 }
51
52 return true;
53};