|
Last change
on this file since 2058e5c was 2058e5c, checked in by istevanoska <ilinastevanoska@…>, 6 months ago |
|
Working / before login
|
-
Property mode
set to
100644
|
|
File size:
1.4 KB
|
| Line | |
|---|
| 1 | class OldSelector {
|
|---|
| 2 | constructor(selector, prefix) {
|
|---|
| 3 | this.prefix = prefix
|
|---|
| 4 | this.prefixed = selector.prefixed(this.prefix)
|
|---|
| 5 | this.regexp = selector.regexp(this.prefix)
|
|---|
| 6 |
|
|---|
| 7 | this.prefixeds = selector
|
|---|
| 8 | .possible()
|
|---|
| 9 | .map(x => [selector.prefixed(x), selector.regexp(x)])
|
|---|
| 10 |
|
|---|
| 11 | this.unprefixed = selector.name
|
|---|
| 12 | this.nameRegexp = selector.regexp()
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | /**
|
|---|
| 16 | * Does rule contain an unnecessary prefixed selector
|
|---|
| 17 | */
|
|---|
| 18 | check(rule) {
|
|---|
| 19 | if (!rule.selector.includes(this.prefixed)) {
|
|---|
| 20 | return false
|
|---|
| 21 | }
|
|---|
| 22 | if (!rule.selector.match(this.regexp)) {
|
|---|
| 23 | return false
|
|---|
| 24 | }
|
|---|
| 25 | if (this.isHack(rule)) {
|
|---|
| 26 | return false
|
|---|
| 27 | }
|
|---|
| 28 | return true
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | /**
|
|---|
| 32 | * Is rule a hack without unprefixed version bottom
|
|---|
| 33 | */
|
|---|
| 34 | isHack(rule) {
|
|---|
| 35 | let index = rule.parent.index(rule) + 1
|
|---|
| 36 | let rules = rule.parent.nodes
|
|---|
| 37 |
|
|---|
| 38 | while (index < rules.length) {
|
|---|
| 39 | let before = rules[index].selector
|
|---|
| 40 | if (!before) {
|
|---|
| 41 | return true
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | if (before.includes(this.unprefixed) && before.match(this.nameRegexp)) {
|
|---|
| 45 | return false
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | let some = false
|
|---|
| 49 | for (let [string, regexp] of this.prefixeds) {
|
|---|
| 50 | if (before.includes(string) && before.match(regexp)) {
|
|---|
| 51 | some = true
|
|---|
| 52 | break
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | if (!some) {
|
|---|
| 57 | return true
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | index += 1
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | return true
|
|---|
| 64 | }
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | module.exports = OldSelector
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.