findAtRuleContext.cjs 701 B

123456789101112131415161718192021222324252627282930313233
  1. // NOTICE: This file is generated by Rollup. To modify it,
  2. // please instead edit the ESM counterpart and rebuild with Rollup (npm run build).
  3. 'use strict';
  4. const typeGuards = require('./typeGuards.cjs');
  5. /**
  6. * Find the at-rule in which a rule is nested.
  7. *
  8. * Returns `null` if the rule is not nested within an at-rule.
  9. *
  10. * @param {import('postcss').Rule} rule
  11. * @returns {null | import('postcss').AtRule}
  12. */
  13. function findAtRuleContext(rule) {
  14. const parent = rule.parent;
  15. if (!parent) {
  16. return null;
  17. }
  18. if (typeGuards.isAtRule(parent)) {
  19. return parent;
  20. }
  21. if (typeGuards.isRule(parent)) {
  22. return findAtRuleContext(parent);
  23. }
  24. return null;
  25. }
  26. module.exports = findAtRuleContext;