getContainingNode.js 478 B

1234567891011121314151617
  1. module.exports = function getContainingNode(node) {
  2. if (node.type === 'rule' || node.type === 'atrule') {
  3. return node;
  4. }
  5. // postcss-styled-syntax: declarations are children of Root node
  6. if (node.parent?.type === 'root' && node.parent?.raws.isRuleLike) {
  7. return node.parent;
  8. }
  9. // @stylelint/postcss-css-in-js: declarations are children of Root node
  10. if (node.parent?.document?.nodes?.some((item) => item.type === 'root')) {
  11. return node.parent;
  12. }
  13. return node;
  14. };