Skip to content

Commit 9666191

Browse files
committed
Fix isPrintable function for comment nodes
1 parent 0ae11a4 commit 9666191

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

src/ast.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,20 @@ namespace Sass {
12521252
}
12531253
}
12541254

1255+
bool Ruleset::is_invisible() const {
1256+
Selector_List* sl = static_cast<Selector_List*>(selector());
1257+
for (size_t i = 0, L = sl->length(); i < L; ++i)
1258+
if (!(*sl)[i]->has_placeholder()) return false;
1259+
return true;
1260+
}
1261+
1262+
bool Media_Block::is_invisible() const {
1263+
for (size_t i = 0, L = block()->length(); i < L; ++i) {
1264+
if (!(*block())[i]->is_invisible()) return false;
1265+
}
1266+
return true;
1267+
}
1268+
12551269
Number::Number(ParserState pstate, double val, std::string u, bool zero)
12561270
: Value(pstate),
12571271
value_(val),

src/ast.hpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,7 @@ namespace Sass {
432432
{ statement_type(MEDIA); }
433433
bool bubbles() { return true; }
434434
bool is_hoistable() { return true; }
435-
bool is_invisible() const {
436-
bool is_invisible = true;
437-
for (size_t i = 0, L = block()->length(); i < L && is_invisible; i++)
438-
is_invisible &= (*block())[i]->is_invisible();
439-
return is_invisible;
440-
}
435+
bool is_invisible() const;
441436
ATTACH_OPERATIONS()
442437
};
443438

@@ -590,6 +585,8 @@ namespace Sass {
590585
Comment(ParserState pstate, String* txt, bool is_important)
591586
: Statement(pstate), text_(txt), is_important_(is_important)
592587
{ statement_type(COMMENT); }
588+
virtual bool is_invisible() const
589+
{ return is_important() == false; }
593590
ATTACH_OPERATIONS()
594591
};
595592

@@ -2250,15 +2247,6 @@ namespace Sass {
22502247
ATTACH_OPERATIONS()
22512248
};
22522249

2253-
inline bool Ruleset::is_invisible() const {
2254-
bool is_invisible = true;
2255-
Selector_List* sl = static_cast<Selector_List*>(selector());
2256-
for (size_t i = 0, L = sl->length(); i < L && is_invisible; ++i)
2257-
is_invisible &= (*sl)[i]->has_placeholder();
2258-
return is_invisible;
2259-
}
2260-
2261-
22622250
template<typename SelectorType>
22632251
bool selectors_equal(const SelectorType& one, const SelectorType& two, bool simpleSelectorOrderDependent) {
22642252
// Test for equality among selectors while differentiating between checks that demand the underlying Simple_Selector

src/util.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,11 +545,14 @@ namespace Sass {
545545
hasPrintableChildBlocks = true;
546546
}
547547
} else if (Comment* c = dynamic_cast<Comment*>(stm)) {
548-
if (style == COMPRESSED) {
549-
hasDeclarations = c->is_important();
550-
} else {
548+
// keep for uncompressed
549+
if (style != COMPRESSED) {
551550
hasDeclarations = true;
552551
}
552+
// output style compressed
553+
if (c->is_important()) {
554+
hasDeclarations = c->is_important();
555+
}
553556
} else if (Declaration* d = dynamic_cast<Declaration*>(stm)) {
554557
return isPrintable(d, style);
555558
} else {
@@ -646,7 +649,15 @@ namespace Sass {
646649
return true;
647650
}
648651
else if (typeid(*stm) == typeid(Comment)) {
649-
652+
Comment* c = (Comment*) stm;
653+
// keep for uncompressed
654+
if (style != COMPRESSED) {
655+
return true;
656+
}
657+
// output style compressed
658+
if (c->is_important()) {
659+
return true;
660+
}
650661
}
651662
else if (typeid(*stm) == typeid(Ruleset)) {
652663
Ruleset* r = (Ruleset*) stm;

0 commit comments

Comments
 (0)