UNPKG

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