isStandardSyntaxSelector.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. 'use strict';
  2. const hasInterpolation = require('../utils/hasInterpolation');
  3. /**
  4. * Check whether a selector is standard
  5. *
  6. * @param {string} selector
  7. * @returns {boolean}
  8. */
  9. module.exports = function isStandardSyntaxSelector(selector) {
  10. // SCSS or Less interpolation
  11. if (hasInterpolation(selector)) {
  12. return false;
  13. }
  14. // SCSS placeholder selectors
  15. if (selector.startsWith('%')) {
  16. return false;
  17. }
  18. // SCSS nested properties
  19. if (selector.endsWith(':')) {
  20. return false;
  21. }
  22. // Less :extend()
  23. if (/:extend(?:\(.*?\))?/.test(selector)) {
  24. return false;
  25. }
  26. // Less mixin with resolved nested selectors (e.g. .foo().bar or .foo(@a, @b)[bar])
  27. if (/\.[\w-]+\(.*\).+/.test(selector)) {
  28. return false;
  29. }
  30. // Less non-outputting mixin definition (e.g. .mixin() {})
  31. if (selector.endsWith(')') && !selector.includes(':')) {
  32. return false;
  33. }
  34. // Less Parametric mixins (e.g. .mixin(@variable: x) {})
  35. if (/\(@.*\)$/.test(selector)) {
  36. return false;
  37. }
  38. // ERB template tags
  39. if (selector.includes('<%') || selector.includes('%>')) {
  40. return false;
  41. }
  42. // SCSS and Less comments
  43. if (selector.includes('//')) {
  44. return false;
  45. }
  46. return true;
  47. };