isDescriptorDeclaration.mjs 635 B

12345678910111213141516171819202122
  1. import findNodeUpToRoot from './findNodeUpToRoot.mjs';
  2. import { isAtRule } from './typeGuards.mjs';
  3. import { nestingSupportedAtKeywords } from '../reference/atKeywords.mjs';
  4. /** @import { Declaration, Node } from 'postcss' */
  5. /**
  6. * Check whether a declaration is a descriptor one
  7. *
  8. * @param {Declaration} decl
  9. * @returns {boolean}
  10. */
  11. export default function isDescriptorDeclaration(decl) {
  12. return Boolean(findNodeUpToRoot(decl, isAtRuleSupportingDescriptors));
  13. }
  14. /**
  15. * @param {Node} node
  16. */
  17. function isAtRuleSupportingDescriptors(node) {
  18. return isAtRule(node) && !nestingSupportedAtKeywords.has(node.name.toLowerCase());
  19. }