Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix is_superselector_of function #1033

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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