Skip to content

Commit 7592d7d

Browse files
committed
Add missing implicit_parent flag to parentize
This is required to prevent some instances of parentizing when we shouldn't like #2006. This isn't a complete fix because we incorrectly add parent refs during parsing which also needs to be addressed.
1 parent d33f45b commit 7592d7d

File tree

6 files changed

+16
-11
lines changed

6 files changed

+16
-11
lines changed

src/ast.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,28 +1084,28 @@ namespace Sass {
10841084

10851085
}
10861086

1087-
Selector_List* Selector_List::parentize(Selector_List* ps, Context& ctx)
1087+
Selector_List* Selector_List::parentize(Selector_List* ps, Context& ctx, bool implicit_parent = true)
10881088
{
1089-
if (!this->has_parent_ref()) return this;
10901089
Selector_List* ss = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
10911090
for (size_t pi = 0, pL = ps->length(); pi < pL; ++pi) {
10921091
Selector_List* list = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
10931092
*list << (*ps)[pi];
10941093
for (size_t si = 0, sL = this->length(); si < sL; ++si) {
1095-
*ss += (*this)[si]->parentize(list, ctx);
1094+
*ss += (*this)[si]->parentize(list, ctx, implicit_parent);
10961095
}
10971096
}
10981097
return ss;
10991098
}
11001099

1101-
Selector_List* Complex_Selector::parentize(Selector_List* parents, Context& ctx)
1100+
Selector_List* Complex_Selector::parentize(Selector_List* parents, Context& ctx, bool implicit_parent)
11021101
{
1102+
if (!this->has_parent_ref()/* && !implicit_parent*/) return this;
11031103

11041104
Complex_Selector* tail = this->tail();
11051105
Compound_Selector* head = this->head();
11061106

11071107
// first parentize the tail (which may return an expanded list)
1108-
Selector_List* tails = tail ? tail->parentize(parents, ctx) : 0;
1108+
Selector_List* tails = tail ? tail->parentize(parents, ctx, implicit_parent) : 0;
11091109

11101110
if (head && head->length() > 0) {
11111111

@@ -1186,7 +1186,7 @@ namespace Sass {
11861186
for (Simple_Selector* ss : *head) {
11871187
if (Wrapped_Selector* ws = dynamic_cast<Wrapped_Selector*>(ss)) {
11881188
if (Selector_List* sl = dynamic_cast<Selector_List*>(ws->selector())) {
1189-
if (parents) ws->selector(sl->parentize(parents, ctx));
1189+
if (parents) ws->selector(sl->parentize(parents, ctx, implicit_parent));
11901190
}
11911191
}
11921192
}

src/ast.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,7 +2404,7 @@ namespace Sass {
24042404
Complex_Selector* innermost() { return last(); };
24052405

24062406
size_t length() const;
2407-
Selector_List* parentize(Selector_List* parents, Context& ctx);
2407+
Selector_List* parentize(Selector_List* parents, Context& ctx, bool implicit_parent = true);
24082408
virtual bool is_superselector_of(Compound_Selector* sub, std::string wrapping = "");
24092409
virtual bool is_superselector_of(Complex_Selector* sub, std::string wrapping = "");
24102410
virtual bool is_superselector_of(Selector_List* sub, std::string wrapping = "");
@@ -2517,7 +2517,7 @@ namespace Sass {
25172517
virtual bool has_parent_ref();
25182518
void remove_parent_selectors();
25192519
// virtual Selector_Placeholder* find_placeholder();
2520-
Selector_List* parentize(Selector_List* parents, Context& ctx);
2520+
Selector_List* parentize(Selector_List* parents, Context& ctx, bool implicit_parent);
25212521
virtual bool is_superselector_of(Compound_Selector* sub, std::string wrapping = "");
25222522
virtual bool is_superselector_of(Complex_Selector* sub, std::string wrapping = "");
25232523
virtual bool is_superselector_of(Selector_List* sub, std::string wrapping = "");

src/eval.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,8 @@ namespace Sass {
16461646

16471647
Selector_List* Eval::operator()(Complex_Selector* s)
16481648
{
1649-
return s->parentize(selector(), ctx);
1649+
bool implicit_parent = !exp.old_at_root_without_rule;
1650+
return s->parentize(selector(), ctx, implicit_parent);
16501651

16511652
}
16521653

src/expand.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ namespace Sass {
2222
media_block_stack(std::vector<Media_Block*>()),
2323
backtrace_stack(std::vector<Backtrace*>()),
2424
in_keyframes(false),
25-
at_root_without_rule(false)
25+
at_root_without_rule(false),
26+
old_at_root_without_rule(false)
2627
{
2728
env_stack.push_back(0);
2829
env_stack.push_back(env);
@@ -87,6 +88,8 @@ namespace Sass {
8788

8889
Statement* Expand::operator()(Ruleset* r)
8990
{
91+
LOCAL_FLAG(old_at_root_without_rule, at_root_without_rule);
92+
9093
if (in_keyframes) {
9194
Keyframe_Rule* k = SASS_MEMORY_NEW(ctx.mem, Keyframe_Rule, r->pstate(), r->block()->perform(this)->block());
9295
if (r->selector()) {

src/expand.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace Sass {
3737
std::vector<Backtrace*> backtrace_stack;
3838
bool in_keyframes;
3939
bool at_root_without_rule;
40+
bool old_at_root_without_rule;
4041

4142
Statement* fallback_impl(AST_Node* n);
4243

src/functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ namespace Sass {
17451745
for(;itr != parsedSelectors.end(); ++itr) {
17461746
Selector_List* child = *itr;
17471747
std::vector<Complex_Selector*> exploded;
1748-
Selector_List* rv = child->parentize(result, ctx);
1748+
Selector_List* rv = child->parentize(result, ctx, true);
17491749
for (size_t m = 0, mLen = rv->length(); m < mLen; ++m) {
17501750
exploded.push_back((*rv)[m]);
17511751
}

0 commit comments

Comments
 (0)