legacyNotSelectorLinter.js 1014 B

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