Coverage Report

Created: 2026-01-17 06:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libsass/src/eval_selectors.cpp
Line
Count
Source
1
// sass.hpp must go before all system headers to get the
2
// __EXTENSIONS__ fix on Solaris.
3
#include "sass.hpp"
4
#include "expand.hpp"
5
#include "eval.hpp"
6
#include "ast.hpp"
7
8
9
namespace Sass {
10
11
  SelectorList* Eval::operator()(SelectorList* s)
12
30
  {
13
30
    sass::vector<SelectorListObj> rv;
14
30
    SelectorListObj sl = SASS_MEMORY_NEW(SelectorList, s->pstate());
15
60
    for (size_t i = 0, iL = s->length(); i < iL; ++i) {
16
30
      rv.push_back(operator()(s->get(i)));
17
30
    }
18
19
    // we should actually permutate parent first
20
    // but here we have permutated the selector first
21
30
    size_t round = 0;
22
90
    while (round != sass::string::npos) {
23
60
      bool abort = true;
24
120
      for (size_t i = 0, iL = rv.size(); i < iL; ++i) {
25
60
        if (rv[i]->length() > round) {
26
30
          sl->append((*rv[i])[round]);
27
30
          abort = false;
28
30
        }
29
60
      }
30
60
      if (abort) {
31
30
        round = sass::string::npos;
32
30
      }
33
30
      else {
34
30
        ++round;
35
30
      }
36
37
60
    }
38
30
    return sl.detach();
39
30
  }
40
41
  SelectorComponent* Eval::operator()(SelectorComponent* s)
42
0
  {
43
0
    return {};
44
0
  }
45
46
  SelectorList* Eval::operator()(ComplexSelector* s)
47
30
  {
48
30
    bool implicit_parent = !exp.old_at_root_without_rule;
49
30
    if (is_in_selector_schema) exp.pushNullSelector();
50
30
    SelectorListObj other = s->resolve_parent_refs(
51
30
      exp.getOriginalStack(), traces, implicit_parent);
52
30
    if (is_in_selector_schema) exp.popNullSelector();
53
54
60
    for (size_t i = 0; i < other->length(); i++) {
55
30
      ComplexSelectorObj sel = other->at(i);
56
62
      for (size_t n = 0; n < sel->length(); n++) {
57
32
        if (CompoundSelectorObj comp = Cast<CompoundSelector>(sel->at(n))) {
58
30
          sel->at(n) = operator()(comp);
59
30
        }
60
32
      }
61
30
    }
62
63
30
    return other.detach();
64
30
  }
65
66
  CompoundSelector* Eval::operator()(CompoundSelector* s)
67
30
  {
68
64
    for (size_t i = 0; i < s->length(); i++) {
69
34
      SimpleSelector* ss = s->at(i);
70
      // skip parents here (called via resolve_parent_refs)
71
34
      s->at(i) = Cast<SimpleSelector>(ss->perform(this));
72
34
    }
73
30
    return s;
74
30
  }
75
}