Skip to content

Commit 97014f3

Browse files
committed
Fix specificity for Simple_Selectors
This better matches the Ruby Sass implementation.
1 parent 05fa158 commit 97014f3

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);
@@ -2034,6 +2034,10 @@ namespace Sass {
20342034
Selector_Placeholder(ParserState pstate, std::string n)
20352035
: Simple_Selector(pstate, n)
20362036
{ has_placeholder(true); }
2037+
virtual unsigned long specificity()
2038+
{
2039+
return Constants::Specificity_Base;
2040+
}
20372041
// virtual Selector_Placeholder* find_placeholder();
20382042
virtual ~Selector_Placeholder() {};
20392043
ATTACH_OPERATIONS()
@@ -2049,8 +2053,7 @@ namespace Sass {
20492053
{ }
20502054
virtual unsigned long specificity()
20512055
{
2052-
// ToDo: What is the specificity of the star selector?
2053-
if (name() == "*") return Constants::Specificity_Universal;
2056+
if (name() == "*") return 0;
20542057
else return Constants::Specificity_Type;
20552058
}
20562059
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)