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

Implement handling of nested :not pseudo selectors #1046

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,8 @@ namespace Sass {
virtual unsigned long specificity() {
return Constants::Specificity_Universal;
};
virtual bool is_child(const string& name) { return false; }
virtual bool has_child(const string& name) { return false; }
};
inline Selector::~Selector() { }

Expand Down Expand Up @@ -1977,6 +1979,13 @@ namespace Sass {
Wrapped_Selector(ParserState pstate, string n, Selector* sel)
: Simple_Selector(pstate), name_(n), selector_(sel)
{ }
virtual bool is_child(const string& name) {
return name_ == name;
}
virtual bool has_child(const string& name) {
if (selector_ == 0) return false;
return selector_->has_child(name);
}
// Selectors inside the negation pseudo-class are counted like any
// other, but the negation itself does not count as a pseudo-class.
virtual unsigned long specificity()
Expand Down Expand Up @@ -2030,6 +2039,13 @@ namespace Sass {
{ sum += (*this)[i]->specificity(); }
return sum;
}
virtual bool has_child(const string& name) {
for (auto el : elements()) {
if (el->is_child(name)) return true;
if (el->has_child(name)) return true;
}
return false;
}
bool is_empty_reference()
{
return length() == 1 &&
Expand Down Expand Up @@ -2091,6 +2107,12 @@ namespace Sass {
if (tail()) sum += tail()->specificity();
return sum;
}
virtual bool has_child(const string& name) {
return (head_ && head_->is_child(name)) ||
(head_ && head_->has_child(name)) ||
(tail_ && tail_->is_child(name)) ||
(tail_ && tail_->has_child(name));
}
bool operator<(const Complex_Selector& rhs) const;
bool operator==(const Complex_Selector& rhs) const;
inline bool operator!=(const Complex_Selector& rhs) const { return !(*this == rhs); }
Expand Down Expand Up @@ -2172,6 +2194,15 @@ namespace Sass {
{ sum += (*this)[i]->specificity(); }
return sum;
}
virtual bool has_child(const string& name)
{
for (size_t i = 0, L = length(); i < L; ++i)
{
if ((*this)[i]->is_child(name)) return true;
if ((*this)[i]->has_child(name)) return true;
}
return false;
}
// vector<Complex_Selector*> members() { return elements_; }
ATTACH_OPERATIONS();
};
Expand Down
10 changes: 10 additions & 0 deletions output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ namespace Sass {

}

void Output::operator()(Wrapped_Selector* s)
{
if (s->name() == ":not(") {
if (s->has_child(":has(") || s->has_child(":not(")) {
return; // abort
}
}
return Inspect::operator()(s);
}

void Output::operator()(Comment* c)
{
To_String to_string(ctx);
Expand Down
1 change: 1 addition & 0 deletions output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace Sass {
virtual void operator()(Media_Block*);
virtual void operator()(At_Rule*);
virtual void operator()(Keyframe_Rule*);
virtual void operator()(Wrapped_Selector*);
virtual void operator()(Import*);
virtual void operator()(Comment*);
virtual void operator()(String_Quoted*);
Expand Down