isContextFunctionalPseudoClass.js 872 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. const {
  3. aNPlusBOfSNotationPseudoClasses,
  4. logicalCombinationsPseudoClasses,
  5. } = require('../reference/selectors');
  6. /**
  7. * Check whether a node is a context-functional pseudo-class (i.e. either a logical combination
  8. * or a 'aNPlusBOfSNotationPseudoClasses' / tree-structural pseudo-class)
  9. *
  10. * @param {import('postcss-selector-parser').Node} node - postcss-selector-parser node (of type pseudo)
  11. * @return {node is import('postcss-selector-parser').Pseudo} If `true`, the node is a context-functional pseudo-class
  12. */
  13. module.exports = function isContextFunctionalPseudoClass(node) {
  14. if (node.type === 'pseudo') {
  15. const normalisedParentName = node.value.toLowerCase().replace(/:+/, '');
  16. return (
  17. logicalCombinationsPseudoClasses.has(normalisedParentName) ||
  18. aNPlusBOfSNotationPseudoClasses.has(normalisedParentName)
  19. );
  20. }
  21. return false;
  22. };