Skip to content

Commit d33f45b

Browse files
committed
Merge pull request #2099 from xzyfer/fix/selector-specificity
Fix specificity for Simple_Selectors
2 parents 5624b9b + 97014f3 commit d33f45b

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/ast.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,7 @@ namespace Sass {
18931893
return false;
18941894
}
18951895
virtual unsigned long specificity() {
1896-
return Constants::Specificity_Universal;
1896+
return 0;
18971897
}
18981898
virtual void set_media_block(Media_Block* mb) {
18991899
media_block(mb);
@@ -2038,6 +2038,10 @@ namespace Sass {
20382038
Selector_Placeholder(ParserState pstate, std::string n)
20392039
: Simple_Selector(pstate, n)
20402040
{ has_placeholder(true); }
2041+
virtual unsigned long specificity()
2042+
{
2043+
return Constants::Specificity_Base;
2044+
}
20412045
// virtual Selector_Placeholder* find_placeholder();
20422046
virtual ~Selector_Placeholder() {};
20432047
ATTACH_OPERATIONS()
@@ -2053,8 +2057,7 @@ namespace Sass {
20532057
{ }
20542058
virtual unsigned long specificity()
20552059
{
2056-
// ToDo: What is the specificity of the star selector?
2057-
if (name() == "*") return Constants::Specificity_Universal;
2060+
if (name() == "*") return 0;
20582061
else return Constants::Specificity_Type;
20592062
}
20602063
virtual Simple_Selector* unify_with(Simple_Selector*, Context&);

src/constants.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ namespace Sass {
1010
// https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
1111
// https://github.com/sass/sass/issues/1495#issuecomment-61189114
1212
extern const unsigned long Specificity_Star = 0;
13-
extern const unsigned long Specificity_Universal = 1 << 0;
14-
extern const unsigned long Specificity_Type = 1 << 8;
15-
extern const unsigned long Specificity_Class = 1 << 16;
16-
extern const unsigned long Specificity_Attr = 1 << 16;
17-
extern const unsigned long Specificity_Pseudo = 1 << 16;
18-
extern const unsigned long Specificity_ID = 1 << 24;
13+
extern const unsigned long Specificity_Universal = 0;
14+
extern const unsigned long Specificity_Type = 1;
15+
extern const unsigned long Specificity_Base = 1000;
16+
extern const unsigned long Specificity_Class = 1000;
17+
extern const unsigned long Specificity_Attr = 1000;
18+
extern const unsigned long Specificity_Pseudo = 1000;
19+
extern const unsigned long Specificity_ID = 1000000;
1920

2021
// sass keywords
2122
extern const char at_root_kwd[] = "@at-root";

src/constants.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace Sass {
1212
extern const unsigned long Specificity_Star;
1313
extern const unsigned long Specificity_Universal;
1414
extern const unsigned long Specificity_Type;
15+
extern const unsigned long Specificity_Base;
1516
extern const unsigned long Specificity_Class;
1617
extern const unsigned long Specificity_Attr;
1718
extern const unsigned long Specificity_Pseudo;

0 commit comments

Comments
 (0)