Skip to content

Commit 66efe5b

Browse files
committed
Merge pull request #1468 from mgreter/bugfix/is-printable-comment
Fix `isPrintable` function for comment nodes
2 parents 4e463b4 + 9666191 commit 66efe5b

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
@@ -1297,6 +1297,20 @@ namespace Sass {
12971297
}
12981298
}
12991299

1300+
bool Ruleset::is_invisible() const {
1301+
Selector_List* sl = static_cast<Selector_List*>(selector());
1302+
for (size_t i = 0, L = sl->length(); i < L; ++i)
1303+
if (!(*sl)[i]->has_placeholder()) return false;
1304+
return true;
1305+
}
1306+
1307+
bool Media_Block::is_invisible() const {
1308+
for (size_t i = 0, L = block()->length(); i < L; ++i) {
1309+
if (!(*block())[i]->is_invisible()) return false;
1310+
}
1311+
return true;
1312+
}
1313+
13001314
Number::Number(ParserState pstate, double val, std::string u, bool zero)
13011315
: Value(pstate),
13021316
value_(val),

src/ast.hpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,7 @@ namespace Sass {
434434
{ statement_type(MEDIA); }
435435
bool bubbles() { return true; }
436436
bool is_hoistable() { return true; }
437-
bool is_invisible() const {
438-
bool is_invisible = true;
439-
for (size_t i = 0, L = block()->length(); i < L && is_invisible; i++)
440-
is_invisible &= (*block())[i]->is_invisible();
441-
return is_invisible;
442-
}
437+
bool is_invisible() const;
443438
ATTACH_OPERATIONS()
444439
};
445440

@@ -592,6 +587,8 @@ namespace Sass {
592587
Comment(ParserState pstate, String* txt, bool is_important)
593588
: Statement(pstate), text_(txt), is_important_(is_important)
594589
{ statement_type(COMMENT); }
590+
virtual bool is_invisible() const
591+
{ return is_important() == false; }
595592
ATTACH_OPERATIONS()
596593
};
597594

@@ -2262,15 +2259,6 @@ namespace Sass {
22622259
ATTACH_OPERATIONS()
22632260
};
22642261

2265-
inline bool Ruleset::is_invisible() const {
2266-
bool is_invisible = true;
2267-
Selector_List* sl = static_cast<Selector_List*>(selector());
2268-
for (size_t i = 0, L = sl->length(); i < L && is_invisible; ++i)
2269-
is_invisible &= (*sl)[i]->has_placeholder();
2270-
return is_invisible;
2271-
}
2272-
2273-
22742262
template<typename SelectorType>
22752263
bool selectors_equal(const SelectorType& one, const SelectorType& two, bool simpleSelectorOrderDependent) {
22762264
// 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)