isStandardSyntaxCombinator.js 817 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. /**
  3. * Check whether a combinator is standard
  4. *
  5. * @param {import('postcss-selector-parser').Combinator} node postcss-selector-parser node (of type combinator)
  6. * @return {boolean} If `true`, the combinator is standard
  7. */
  8. module.exports = function (node) {
  9. // if it's not a combinator, then it's not a standard combinator
  10. if (node.type !== 'combinator') {
  11. return false;
  12. }
  13. // Ignore reference combinators like `/deep/`
  14. if (node.value.startsWith('/') || node.value.endsWith('/')) {
  15. return false;
  16. }
  17. // ignore the combinators that are the first or last node in their container
  18. if (node.parent !== undefined && node.parent !== null) {
  19. const parent = node.parent;
  20. if (node === parent.first) {
  21. return false;
  22. }
  23. if (node === parent.last) {
  24. return false;
  25. }
  26. }
  27. return true;
  28. };