getContainingNode.js 349 B

1234567891011121314
  1. module.exports = function getContainingNode(node) {
  2. // For styled-components declarations are children of Root node
  3. if (
  4. node.type !== 'rule' &&
  5. node.type !== 'atrule' &&
  6. node.parent.document &&
  7. node.parent.document.nodes &&
  8. node.parent.document.nodes.some((item) => item.type === 'root')
  9. ) {
  10. return node.parent;
  11. }
  12. return node;
  13. };