getSelectorSourceIndex.mjs 452 B

123456789101112
  1. /**
  2. * Get the source index of a selector, excluding leading whitespace.
  3. *
  4. * @param {import('postcss-selector-parser').Selector} node
  5. *
  6. * @returns {number}
  7. */
  8. export default function getSelectorSourceIndex(node) {
  9. // The first child node sourceIndex is the same as the parent sourceIndex without leading whitespace
  10. // If the node doesn't have any children, use the node sourceIndex instead
  11. return node.first?.sourceIndex ?? node.sourceIndex;
  12. }