isStandardSyntaxCombinator.mjs 826 B

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