Skip to content

Commit

Permalink
Fix isPrintable functions for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Apr 5, 2016
1 parent 7468ac6 commit f6f2064
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ namespace Sass {
: Statement(pstate), text_(txt), is_important_(is_important)
{ statement_type(COMMENT); }
virtual bool is_invisible() const
{ return is_important() == false; }
{ return /* is_important() == */ false; }
ATTACH_OPERATIONS()
};

Expand Down
51 changes: 42 additions & 9 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,14 +566,52 @@ namespace Sass {
for (size_t i = 0, L = b->length(); i < L; ++i) {
Statement* stm = (*b)[i];
if (typeid(*stm) == typeid(At_Rule)) return true;
if (typeid(*stm) == typeid(Declaration)) return true;
if (Has_Block* child = dynamic_cast<Has_Block*>(stm)) {
if (isPrintable(child->block(), style)) return true;
else if (typeid(*stm) == typeid(Declaration)) return true;
else if (typeid(*stm) == typeid(Comment)) {
Comment* c = (Comment*) stm;
if (isPrintable(c, style)) {
return true;
}
}
else if (typeid(*stm) == typeid(Ruleset)) {
Ruleset* r = (Ruleset*) stm;
if (isPrintable(r, style)) {
return true;
}
}
else if (typeid(*stm) == typeid(Supports_Block)) {
Supports_Block* f = (Supports_Block*) stm;
if (isPrintable(f, style)) {
return true;
}
}
else if (typeid(*stm) == typeid(Media_Block)) {
Media_Block* m = (Media_Block*) stm;
if (isPrintable(m, style)) {
return true;
}
}
else if (dynamic_cast<Has_Block*>(stm) && isPrintable(((Has_Block*)stm)->block(), style)) {
return true;
}
}
return false;
}

bool isPrintable(Comment* c, Sass_Output_Style style)
{
// keep for uncompressed
if (style != COMPRESSED) {
return true;
}
// output style compressed
if (c->is_important()) {
return true;
}
// not printable
return false;
};

bool isPrintable(Block* b, Sass_Output_Style style) {
if (b == NULL) {
return false;
Expand All @@ -586,12 +624,7 @@ namespace Sass {
}
else if (typeid(*stm) == typeid(Comment)) {
Comment* c = (Comment*) stm;
// keep for uncompressed
if (style != COMPRESSED) {
return true;
}
// output style compressed
if (c->is_important()) {
if (isPrintable(c, style)) {
return true;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace Sass {
bool isPrintable(Ruleset* r, Sass_Output_Style style = NESTED);
bool isPrintable(Supports_Block* r, Sass_Output_Style style = NESTED);
bool isPrintable(Media_Block* r, Sass_Output_Style style = NESTED);
bool isPrintable(Comment* b, Sass_Output_Style style = NESTED);
bool isPrintable(Block* b, Sass_Output_Style style = NESTED);
bool isPrintable(String_Constant* s, Sass_Output_Style style = NESTED);
bool isPrintable(String_Quoted* s, Sass_Output_Style style = NESTED);
Expand Down

0 comments on commit f6f2064

Please sign in to comment.