Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 5312136

Browse files
committed
Implement static selector namespace handling
Missing implementation for interpolated namespaces!
1 parent 7514f0e commit 5312136

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

ast.hpp

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,10 +1729,27 @@ namespace Sass {
17291729
// Abstract base class for simple selectors.
17301730
////////////////////////////////////////////
17311731
class Simple_Selector : public Selector {
1732+
ADD_PROPERTY(string, ns);
1733+
ADD_PROPERTY(string, name)
17321734
public:
1733-
Simple_Selector(ParserState pstate)
1734-
: Selector(pstate)
1735-
{ }
1735+
Simple_Selector(ParserState pstate, string n = "")
1736+
: Selector(pstate), ns_(""), name_(n)
1737+
{
1738+
size_t pos = n.find('|');
1739+
// found some namespace
1740+
if (pos != string::npos) {
1741+
ns_ = n.substr(0, pos);
1742+
name_ = n.substr(pos + 1);
1743+
}
1744+
}
1745+
virtual string ns_name() const
1746+
{
1747+
string name("");
1748+
if (!ns_.empty())
1749+
name += ns_ + "|";
1750+
return name + name_;
1751+
}
1752+
17361753
virtual ~Simple_Selector() = 0;
17371754
virtual Compound_Selector* unify_with(Compound_Selector*, Context&);
17381755
virtual bool has_parent_ref() { return false; };
@@ -1745,6 +1762,7 @@ namespace Sass {
17451762
inline bool operator!=(const Simple_Selector& rhs) const { return !(*this == rhs); }
17461763

17471764
bool operator<(const Simple_Selector& rhs) const;
1765+
ATTACH_OPERATIONS();
17481766
};
17491767
inline Simple_Selector::~Simple_Selector() { }
17501768

@@ -1758,7 +1776,7 @@ namespace Sass {
17581776
class Parent_Selector : public Simple_Selector {
17591777
public:
17601778
Parent_Selector(ParserState pstate)
1761-
: Simple_Selector(pstate)
1779+
: Simple_Selector(pstate, "&")
17621780
{ has_reference(true); }
17631781
virtual bool has_parent_ref() { return true; };
17641782
virtual unsigned long specificity()
@@ -1774,10 +1792,9 @@ namespace Sass {
17741792
// Placeholder selectors (e.g., "%foo") for use in extend-only selectors.
17751793
/////////////////////////////////////////////////////////////////////////
17761794
class Selector_Placeholder : public Simple_Selector {
1777-
ADD_PROPERTY(string, name)
17781795
public:
17791796
Selector_Placeholder(ParserState pstate, string n)
1780-
: Simple_Selector(pstate), name_(n)
1797+
: Simple_Selector(pstate, n)
17811798
{ has_placeholder(true); }
17821799
// virtual Selector_Placeholder* find_placeholder();
17831800
ATTACH_OPERATIONS()
@@ -1787,10 +1804,9 @@ namespace Sass {
17871804
// Type selectors (and the universal selector) -- e.g., div, span, *.
17881805
/////////////////////////////////////////////////////////////////////
17891806
class Type_Selector : public Simple_Selector {
1790-
ADD_PROPERTY(string, name)
17911807
public:
17921808
Type_Selector(ParserState pstate, string n)
1793-
: Simple_Selector(pstate), name_(n)
1809+
: Simple_Selector(pstate, n)
17941810
{ }
17951811
virtual unsigned long specificity()
17961812
{
@@ -1806,10 +1822,9 @@ namespace Sass {
18061822
// Selector qualifiers -- i.e., classes and ids.
18071823
////////////////////////////////////////////////
18081824
class Selector_Qualifier : public Simple_Selector {
1809-
ADD_PROPERTY(string, name)
18101825
public:
18111826
Selector_Qualifier(ParserState pstate, string n)
1812-
: Simple_Selector(pstate), name_(n)
1827+
: Simple_Selector(pstate, n)
18131828
{ }
18141829
virtual unsigned long specificity()
18151830
{
@@ -1825,12 +1840,11 @@ namespace Sass {
18251840
// Attribute selectors -- e.g., [src*=".jpg"], etc.
18261841
///////////////////////////////////////////////////
18271842
class Attribute_Selector : public Simple_Selector {
1828-
ADD_PROPERTY(string, name)
18291843
ADD_PROPERTY(string, matcher)
18301844
ADD_PROPERTY(String*, value) // might be interpolated
18311845
public:
18321846
Attribute_Selector(ParserState pstate, string n, string m, String* v)
1833-
: Simple_Selector(pstate), name_(n), matcher_(m), value_(v)
1847+
: Simple_Selector(pstate, n), matcher_(m), value_(v)
18341848
{ }
18351849
virtual unsigned long specificity()
18361850
{
@@ -1855,11 +1869,10 @@ namespace Sass {
18551869
}
18561870

18571871
class Pseudo_Selector : public Simple_Selector {
1858-
ADD_PROPERTY(string, name)
18591872
ADD_PROPERTY(String*, expression)
18601873
public:
18611874
Pseudo_Selector(ParserState pstate, string n, String* expr = 0)
1862-
: Simple_Selector(pstate), name_(n), expression_(expr)
1875+
: Simple_Selector(pstate, n), expression_(expr)
18631876
{ }
18641877

18651878
// A pseudo-class always consists of a "colon" (:) followed by the name
@@ -1897,11 +1910,10 @@ namespace Sass {
18971910
// Wrapped selector -- pseudo selector that takes a list of selectors as argument(s) e.g., :not(:first-of-type), :-moz-any(ol p.blah, ul, menu, dir)
18981911
/////////////////////////////////////////////////
18991912
class Wrapped_Selector : public Simple_Selector {
1900-
ADD_PROPERTY(string, name)
19011913
ADD_PROPERTY(Selector*, selector)
19021914
public:
19031915
Wrapped_Selector(ParserState pstate, string n, Selector* sel)
1904-
: Simple_Selector(pstate), name_(n), selector_(sel)
1916+
: Simple_Selector(pstate, n), selector_(sel)
19051917
{ }
19061918
virtual bool is_superselector_of(Wrapped_Selector* sub);
19071919
// Selectors inside the negation pseudo-class are counted like any

inspect.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -837,12 +837,12 @@ namespace Sass {
837837

838838
void Inspect::operator()(Type_Selector* s)
839839
{
840-
append_token(s->name(), s);
840+
append_token(s->ns_name(), s);
841841
}
842842

843843
void Inspect::operator()(Selector_Qualifier* s)
844844
{
845-
append_token(s->name(), s);
845+
append_token(s->ns_name(), s);
846846
if (s->has_line_break()) append_optional_linefeed();
847847
if (s->has_line_break()) append_indentation();
848848
}
@@ -851,7 +851,7 @@ namespace Sass {
851851
{
852852
append_string("[");
853853
add_open_mapping(s);
854-
append_token(s->name(), s);
854+
append_token(s->ns_name(), s);
855855
if (!s->matcher().empty()) {
856856
append_string(s->matcher());
857857
if (s->value()) {
@@ -864,7 +864,7 @@ namespace Sass {
864864

865865
void Inspect::operator()(Pseudo_Selector* s)
866866
{
867-
append_token(s->name(), s);
867+
append_token(s->ns_name(), s);
868868
if (s->expression()) {
869869
append_string("(");
870870
s->expression()->perform(this);

parser.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,8 @@ namespace Sass {
21452145
// main selector match
21462146
sequence <
21472147
// allow namespace prefix
2148+
optional < namespace_prefix >,
2149+
// modifiers prefixes
21482150
alternatives <
21492151
sequence <
21502152
exactly <'#'>,
@@ -2157,14 +2159,13 @@ namespace Sass {
21572159
optional < pseudo_prefix >
21582160
>,
21592161
// accept hypens in token
2160-
optional < namespace_prefix >,
2161-
// accept hypens in token
21622162
one_plus < sequence <
21632163
// can start with hyphens
21642164
zero_plus < exactly<'-'> >,
21652165
// now the main token
21662166
alternatives <
21672167
kwd_optional,
2168+
exactly <'*'>,
21682169
quoted_string,
21692170
interpolant,
21702171
identifier,

0 commit comments

Comments
 (0)