hasInterpolatingAmpersand.js 893 B

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = _default;
  6. /**
  7. * Check whether a selector has an interpolating ampersand
  8. * An "interpolating ampersand" is an "&" used to interpolate within another
  9. * simple selector (e.g. `&-modifier`), rather than an "&" that stands
  10. * on its own as a simple selector (e.g. `& .child`)
  11. *
  12. * @param {string} selector
  13. * @return {boolean} If `true`, the selector has an interpolating ampersand
  14. */
  15. function _default(selector) {
  16. for (var i = 0; i < selector.length; i++) {
  17. if (selector[i] !== "&") {
  18. continue;
  19. }
  20. if (selector[i - 1] !== undefined && !isCombinator(selector[i - 1])) {
  21. return true;
  22. }
  23. if (selector[i + 1] !== undefined && !isCombinator(selector[i + 1])) {
  24. return true;
  25. }
  26. }
  27. return false;
  28. }
  29. function isCombinator(x) {
  30. return /[\s+>~]/.test(x);
  31. }