Skip to content

Commit 1a8d6dd

Browse files
committed
Do not compress colors in selectors
1 parent 6f77335 commit 1a8d6dd

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
@@ -1798,8 +1798,10 @@ namespace Sass {
17981798
{
17991799
LOCAL_FLAG(is_in_selector_schema, true);
18001800
// the parser will look for a brace to end the selector
1801+
ctx.c_options.in_selector = true; // do not compress colors
18011802
Expression_Obj sel = s->contents()->perform(this);
18021803
std::string result_str(sel->to_string(ctx.c_options));
1804+
ctx.c_options.in_selector = false; // flag temporary only
18031805
result_str = unquote(Util::rtrim(result_str));
18041806
char* temp_cstr = sass_copy_c_string(result_str.c_str());
18051807
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);
@@ -600,6 +602,11 @@ namespace Sass {
600602
// maybe an unknown token
601603
std::string name = c->disp();
602604

605+
if (opt.in_selector && name != "") {
606+
append_token(name, c);
607+
return;
608+
}
609+
603610
// resolved color
604611
std::string res_name = name;
605612

@@ -879,7 +886,9 @@ namespace Sass {
879886

880887
void Inspect::operator()(Selector_Schema_Ptr s)
881888
{
889+
opt.in_selector = true;
882890
s->contents()->perform(this);
891+
opt.in_selector = false;
883892
}
884893

885894
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)