Skip to content

Commit 9eb7b33

Browse files
authored
Merge pull request #2354 from mgreter/bugfix/issue-2347
Fix Element Selector compare operators
2 parents 89723b6 + 4b7dd82 commit 9eb7b33

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/ast.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ namespace Sass {
379379
// solve the double dispatch problem by using RTTI information via dynamic cast
380380
if (const Pseudo_Selector* lhs = Cast<Pseudo_Selector>(this)) {return *lhs == rhs; }
381381
else if (const Wrapped_Selector* lhs = Cast<Wrapped_Selector>(this)) {return *lhs == rhs; }
382+
else if (const Element_Selector* lhs = Cast<Element_Selector>(this)) {return *lhs == rhs; }
382383
else if (const Attribute_Selector* lhs = Cast<Attribute_Selector>(this)) {return *lhs == rhs; }
383384
else if (name_ == rhs.name_)
384385
{ return is_ns_eq(rhs); }
@@ -390,6 +391,7 @@ namespace Sass {
390391
// solve the double dispatch problem by using RTTI information via dynamic cast
391392
if (const Pseudo_Selector* lhs = Cast<Pseudo_Selector>(this)) {return *lhs < rhs; }
392393
else if (const Wrapped_Selector* lhs = Cast<Wrapped_Selector>(this)) {return *lhs < rhs; }
394+
else if (const Element_Selector* lhs = Cast<Element_Selector>(this)) {return *lhs < rhs; }
393395
else if (const Attribute_Selector* lhs = Cast<Attribute_Selector>(this)) {return *lhs < rhs; }
394396
if (is_ns_eq(rhs))
395397
{ return name_ < rhs.name_; }
@@ -668,6 +670,41 @@ namespace Sass {
668670
return false;
669671
}
670672

673+
bool Element_Selector::operator< (const Element_Selector& rhs) const
674+
{
675+
if (is_ns_eq(rhs))
676+
{ return name() < rhs.name(); }
677+
return ns() < rhs.ns();
678+
}
679+
680+
bool Element_Selector::operator< (const Simple_Selector& rhs) const
681+
{
682+
if (Element_Selector_Ptr_Const w = Cast<Element_Selector>(&rhs))
683+
{
684+
return *this < *w;
685+
}
686+
if (is_ns_eq(rhs))
687+
{ return name() < rhs.name(); }
688+
return ns() < rhs.ns();
689+
}
690+
691+
bool Element_Selector::operator== (const Element_Selector& rhs) const
692+
{
693+
return is_ns_eq(rhs) &&
694+
name() == rhs.name();
695+
}
696+
697+
bool Element_Selector::operator== (const Simple_Selector& rhs) const
698+
{
699+
if (Element_Selector_Ptr_Const w = Cast<Element_Selector>(&rhs))
700+
{
701+
return is_ns_eq(rhs) &&
702+
name() == rhs.name() &&
703+
*this == *w;
704+
}
705+
return false;
706+
}
707+
671708
bool Pseudo_Selector::operator== (const Pseudo_Selector& rhs) const
672709
{
673710
if (is_ns_eq(rhs) && name() == rhs.name())

src/ast.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,6 +2477,10 @@ namespace Sass {
24772477
}
24782478
virtual Simple_Selector_Ptr unify_with(Simple_Selector_Ptr);
24792479
virtual Compound_Selector_Ptr unify_with(Compound_Selector_Ptr);
2480+
virtual bool operator==(const Simple_Selector& rhs) const;
2481+
virtual bool operator==(const Element_Selector& rhs) const;
2482+
virtual bool operator<(const Simple_Selector& rhs) const;
2483+
virtual bool operator<(const Element_Selector& rhs) const;
24802484
ATTACH_AST_OPERATIONS(Element_Selector)
24812485
ATTACH_OPERATIONS()
24822486
};

0 commit comments

Comments
 (0)