legacyNotSelectorLinter.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _utils = require("./utils");
  7. function isConcatSelector(selector) {
  8. var _selector$match;
  9. var notContent = ((_selector$match = selector.match(/:not\(([^)]*)\)/)) === null || _selector$match === void 0 ? void 0 : _selector$match[1]) || '';
  10. // split selector. e.g.
  11. // `h1#a.b` => ['h1', #a', '.b']
  12. var splitCells = notContent.split(/(\[[^[]*])|(?=[.#])/).filter(function (str) {
  13. return str;
  14. });
  15. return splitCells.length > 1;
  16. }
  17. function parsePath(info) {
  18. return info.parentSelectors.reduce(function (prev, cur) {
  19. if (!prev) {
  20. return cur;
  21. }
  22. return cur.includes('&') ? cur.replace(/&/g, prev) : "".concat(prev, " ").concat(cur);
  23. }, '');
  24. }
  25. var linter = function linter(key, value, info) {
  26. var parentSelectorPath = parsePath(info);
  27. var notList = parentSelectorPath.match(/:not\([^)]*\)/g) || [];
  28. if (notList.length > 0 && notList.some(isConcatSelector)) {
  29. (0, _utils.lintWarning)("Concat ':not' selector not support in legacy browsers.", info);
  30. }
  31. };
  32. var _default = exports.default = linter;