isStandardSyntaxSelector.cjs 1.3 KB

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