You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.0 KiB

4 years ago
  1. "use strict";
  2. var OldSelector =
  3. /*#__PURE__*/
  4. function () {
  5. function OldSelector(selector, prefix) {
  6. this.prefix = prefix;
  7. this.prefixed = selector.prefixed(this.prefix);
  8. this.regexp = selector.regexp(this.prefix);
  9. this.prefixeds = selector.possible().map(function (x) {
  10. return [selector.prefixed(x), selector.regexp(x)];
  11. });
  12. this.unprefixed = selector.name;
  13. this.nameRegexp = selector.regexp();
  14. }
  15. /**
  16. * Is rule a hack without unprefixed version bottom
  17. */
  18. var _proto = OldSelector.prototype;
  19. _proto.isHack = function isHack(rule) {
  20. var index = rule.parent.index(rule) + 1;
  21. var rules = rule.parent.nodes;
  22. while (index < rules.length) {
  23. var before = rules[index].selector;
  24. if (!before) {
  25. return true;
  26. }
  27. if (before.includes(this.unprefixed) && before.match(this.nameRegexp)) {
  28. return false;
  29. }
  30. var some = false;
  31. for (var _iterator = this.prefixeds, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
  32. var _ref;
  33. if (_isArray) {
  34. if (_i >= _iterator.length) break;
  35. _ref = _iterator[_i++];
  36. } else {
  37. _i = _iterator.next();
  38. if (_i.done) break;
  39. _ref = _i.value;
  40. }
  41. var _ref2 = _ref,
  42. string = _ref2[0],
  43. regexp = _ref2[1];
  44. if (before.includes(string) && before.match(regexp)) {
  45. some = true;
  46. break;
  47. }
  48. }
  49. if (!some) {
  50. return true;
  51. }
  52. index += 1;
  53. }
  54. return true;
  55. }
  56. /**
  57. * Does rule contain an unnecessary prefixed selector
  58. */
  59. ;
  60. _proto.check = function check(rule) {
  61. if (!rule.selector.includes(this.prefixed)) {
  62. return false;
  63. }
  64. if (!rule.selector.match(this.regexp)) {
  65. return false;
  66. }
  67. if (this.isHack(rule)) {
  68. return false;
  69. }
  70. return true;
  71. };
  72. return OldSelector;
  73. }();
  74. module.exports = OldSelector;