legacyNotSelectorLinter.js 913 B

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