isStandardSyntaxDeclaration.js 1.2 KB

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