Skip to content

Commit

Permalink
Fix is_superselector_of function
Browse files Browse the repository at this point in the history
Fixes sass#823
  • Loading branch information
mgreter committed Apr 2, 2015
1 parent fd7f20f commit 625a2a0
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,30 +336,34 @@ namespace Sass {
// check for selectors with leading or trailing combinators
if (!lhs->head() || !rhs->head())
{ return false; }
Complex_Selector* l_innermost = lhs->innermost();
if (l_innermost->combinator() != Complex_Selector::ANCESTOR_OF && !l_innermost->tail())
{ return false; }
Complex_Selector* r_innermost = rhs->innermost();
if (r_innermost->combinator() != Complex_Selector::ANCESTOR_OF && !r_innermost->tail())
{ return false; }

// more complex (i.e., longer) selectors are always more specific
size_t l_len = lhs->length(), r_len = rhs->length();
if (l_len > r_len)
{ return false; }

if (l_len == 1)
{ return lhs->head()->is_superselector_of(rhs->base()); }
{
// compare ancestor only with base selectors
if (combinator() == Complex_Selector::ANCESTOR_OF &&
rhs->combinator() == Complex_Selector::ANCESTOR_OF)
{ return lhs->base()->is_superselector_of(rhs->base()); }
// compare combinator plus lhs and rhs
return combinator() == rhs->combinator() &&
head()->is_superselector_of(rhs->head()) &&
tail()->is_superselector_of(rhs->tail());
}

bool found = false;
bool abort = true;
Complex_Selector* marker = rhs;
for (size_t i = 0, L = rhs->length(); i < L; ++i) {
if (i == L-1)
{ return false; }
if (lhs->head()->is_superselector_of(marker->head()))
{ found = true; break; }
{ abort = false; break; }
marker = marker->tail();
}
if (!found)
if (abort)
{ return false; }

/*
Expand Down

0 comments on commit 625a2a0

Please # to comment.