legacyNotSelectorLinter.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  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 _a;
  9. const notContent = ((_a = selector.match(/:not\(([^)]*)\)/)) === null || _a === void 0 ? void 0 : _a[1]) || '';
  10. // split selector. e.g.
  11. // `h1#a.b` => ['h1', #a', '.b']
  12. const splitCells = notContent.split(/(\[[^[]*])|(?=[.#])/).filter(str => str);
  13. return splitCells.length > 1;
  14. }
  15. function parsePath(info) {
  16. return info.parentSelectors.reduce((prev, cur) => {
  17. if (!prev) {
  18. return cur;
  19. }
  20. return cur.includes('&') ? cur.replace(/&/g, prev) : `${prev} ${cur}`;
  21. }, '');
  22. }
  23. const linter = (_key, _value, info) => {
  24. const parentSelectorPath = parsePath(info);
  25. const notList = parentSelectorPath.match(/:not\([^)]*\)/g) || [];
  26. if (notList.length > 0 && notList.some(isConcatSelector)) {
  27. (0, _utils.lintWarning)(`Concat ':not' selector not support in legacy browsers.`, info);
  28. }
  29. };
  30. var _default = exports.default = linter;