isStandardSyntaxDeclaration.cjs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. const isScssVariable = require('./isScssVariable.cjs');
  6. /**
  7. * Check whether a declaration is standard
  8. *
  9. * @param {import('postcss').Declaration | import('postcss-less').Declaration} decl
  10. * @returns {boolean}
  11. */
  12. function isStandardSyntaxDeclaration(decl) {
  13. const prop = decl.prop;
  14. const parent = decl.parent;
  15. // SCSS var; covers map and list declarations
  16. if (isScssVariable(prop)) {
  17. return false;
  18. }
  19. // Less var (e.g. @var: x), but exclude variable interpolation (e.g. @{var})
  20. if (prop[0] === '@' && prop[1] !== '{') {
  21. return false;
  22. }
  23. // Less map declaration
  24. if (parent && parent.type === 'atrule' && parent.raws.afterName === ':') {
  25. return false;
  26. }
  27. // Less map (e.g. #my-map() { myprop: red; })
  28. if (
  29. parent &&
  30. typeGuards.isRule(parent) &&
  31. parent.selector &&
  32. parent.selector.startsWith('#') &&
  33. parent.selector.endsWith('()')
  34. ) {
  35. return false;
  36. }
  37. // Sass nested properties (e.g. border: { style: solid; color: red; })
  38. if (
  39. parent &&
  40. typeGuards.isRule(parent) &&
  41. parent.selector &&
  42. parent.selector[parent.selector.length - 1] === ':' &&
  43. parent.selector.substring(0, 2) !== '--'
  44. ) {
  45. return false;
  46. }
  47. // Less &:extend
  48. if ('extend' in decl && decl.extend) {
  49. return false;
  50. }
  51. return true;
  52. }
  53. module.exports = isStandardSyntaxDeclaration;