isStandardSyntaxAtRule.mjs 857 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Check whether a at-rule is standard
  3. *
  4. * @param {import('postcss').AtRule | import('postcss-less').AtRule} atRule postcss at-rule node
  5. * @returns {boolean} If `true`, the declaration is standard
  6. */
  7. export default function isStandardSyntaxAtRule(atRule) {
  8. // Ignore `@charset` css rule (is parsed as at-rule)
  9. if (atRule.name.toLowerCase() === 'charset') {
  10. return false;
  11. }
  12. // Ignore scss `@content` inside mixins
  13. if (!atRule.nodes && atRule.params === '') {
  14. return false;
  15. }
  16. // Ignore Less mixins
  17. if ('mixin' in atRule && atRule.mixin) {
  18. return false;
  19. }
  20. // Ignore Less detached ruleset `@detached-ruleset: { background: red; }; .top { @detached-ruleset(); }`
  21. if (
  22. ('variable' in atRule && atRule.variable) ||
  23. (!atRule.nodes && atRule.raws.afterName === '' && atRule.params[0] === '(')
  24. ) {
  25. return false;
  26. }
  27. return true;
  28. }