Skip to content

Commit 7e51fad

Browse files
authored
Merge pull request #2502 from mgreter/bugfix/issue-2232
Do not compress colors in selectors
2 parents e88b2e2 + 9973a01 commit 7e51fad

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/eval.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,8 +1804,10 @@ namespace Sass {
18041804
{
18051805
LOCAL_FLAG(is_in_selector_schema, true);
18061806
// the parser will look for a brace to end the selector
1807+
ctx.c_options.in_selector = true; // do not compress colors
18071808
Expression_Obj sel = s->contents()->perform(this);
18081809
std::string result_str(sel->to_string(ctx.c_options));
1810+
ctx.c_options.in_selector = false; // flag temporary only
18091811
result_str = unquote(Util::rtrim(result_str));
18101812
char* temp_cstr = sass_copy_c_string(result_str.c_str());
18111813
ctx.strings.push_back(temp_cstr); // attach to context

src/inspect.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ namespace Sass {
4242
void Inspect::operator()(Ruleset_Ptr ruleset)
4343
{
4444
if (ruleset->selector()) {
45+
opt.in_selector = true;
4546
ruleset->selector()->perform(this);
47+
opt.in_selector = false;
4648
}
4749
if (ruleset->block()) {
4850
ruleset->block()->perform(this);
@@ -622,6 +624,11 @@ namespace Sass {
622624
// maybe an unknown token
623625
std::string name = c->disp();
624626

627+
if (opt.in_selector && name != "") {
628+
append_token(name, c);
629+
return;
630+
}
631+
625632
// resolved color
626633
std::string res_name = name;
627634

@@ -909,7 +916,9 @@ namespace Sass {
909916

910917
void Inspect::operator()(Selector_Schema_Ptr s)
911918
{
919+
opt.in_selector = true;
912920
s->contents()->perform(this);
921+
opt.in_selector = false;
913922
}
914923

915924
void Inspect::operator()(Parent_Selector_Ptr p)

src/sass.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,13 @@ struct Sass_Inspect_Options {
9090
// Precision for fractional numbers
9191
int precision;
9292

93+
// Do not compress colors in selectors
94+
bool in_selector;
95+
9396
// initialization list (constructor with defaults)
9497
Sass_Inspect_Options(Sass_Output_Style style = Sass::NESTED,
95-
int precision = 5)
96-
: output_style(style), precision(precision)
98+
int precision = 5, bool in_selector = false)
99+
: output_style(style), precision(precision), in_selector(in_selector)
97100
{ }
98101

99102
};

0 commit comments

Comments
 (0)