Skip to content

Commit f6f2064

Browse files
committed
Fix isPrintable functions for comments
1 parent 7468ac6 commit f6f2064

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

src/ast.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ namespace Sass {
660660
: Statement(pstate), text_(txt), is_important_(is_important)
661661
{ statement_type(COMMENT); }
662662
virtual bool is_invisible() const
663-
{ return is_important() == false; }
663+
{ return /* is_important() == */ false; }
664664
ATTACH_OPERATIONS()
665665
};
666666

src/util.cpp

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -566,14 +566,52 @@ namespace Sass {
566566
for (size_t i = 0, L = b->length(); i < L; ++i) {
567567
Statement* stm = (*b)[i];
568568
if (typeid(*stm) == typeid(At_Rule)) return true;
569-
if (typeid(*stm) == typeid(Declaration)) return true;
570-
if (Has_Block* child = dynamic_cast<Has_Block*>(stm)) {
571-
if (isPrintable(child->block(), style)) return true;
569+
else if (typeid(*stm) == typeid(Declaration)) return true;
570+
else if (typeid(*stm) == typeid(Comment)) {
571+
Comment* c = (Comment*) stm;
572+
if (isPrintable(c, style)) {
573+
return true;
574+
}
575+
}
576+
else if (typeid(*stm) == typeid(Ruleset)) {
577+
Ruleset* r = (Ruleset*) stm;
578+
if (isPrintable(r, style)) {
579+
return true;
580+
}
581+
}
582+
else if (typeid(*stm) == typeid(Supports_Block)) {
583+
Supports_Block* f = (Supports_Block*) stm;
584+
if (isPrintable(f, style)) {
585+
return true;
586+
}
587+
}
588+
else if (typeid(*stm) == typeid(Media_Block)) {
589+
Media_Block* m = (Media_Block*) stm;
590+
if (isPrintable(m, style)) {
591+
return true;
592+
}
593+
}
594+
else if (dynamic_cast<Has_Block*>(stm) && isPrintable(((Has_Block*)stm)->block(), style)) {
595+
return true;
572596
}
573597
}
574598
return false;
575599
}
576600

601+
bool isPrintable(Comment* c, Sass_Output_Style style)
602+
{
603+
// keep for uncompressed
604+
if (style != COMPRESSED) {
605+
return true;
606+
}
607+
// output style compressed
608+
if (c->is_important()) {
609+
return true;
610+
}
611+
// not printable
612+
return false;
613+
};
614+
577615
bool isPrintable(Block* b, Sass_Output_Style style) {
578616
if (b == NULL) {
579617
return false;
@@ -586,12 +624,7 @@ namespace Sass {
586624
}
587625
else if (typeid(*stm) == typeid(Comment)) {
588626
Comment* c = (Comment*) stm;
589-
// keep for uncompressed
590-
if (style != COMPRESSED) {
591-
return true;
592-
}
593-
// output style compressed
594-
if (c->is_important()) {
627+
if (isPrintable(c, style)) {
595628
return true;
596629
}
597630
}

src/util.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace Sass {
4646
bool isPrintable(Ruleset* r, Sass_Output_Style style = NESTED);
4747
bool isPrintable(Supports_Block* r, Sass_Output_Style style = NESTED);
4848
bool isPrintable(Media_Block* r, Sass_Output_Style style = NESTED);
49+
bool isPrintable(Comment* b, Sass_Output_Style style = NESTED);
4950
bool isPrintable(Block* b, Sass_Output_Style style = NESTED);
5051
bool isPrintable(String_Constant* s, Sass_Output_Style style = NESTED);
5152
bool isPrintable(String_Quoted* s, Sass_Output_Style style = NESTED);

0 commit comments

Comments
 (0)