Skip to content

Commit

Permalink
Add missing implicit_parent flag to parentize
Browse files Browse the repository at this point in the history
This is required to prevent some instances of parentizing when we
shouldn't like sass#2006. This isn't a complete fix because we incorrectly
add parent refs during parsing which also needs to be addressed.
  • Loading branch information
xzyfer committed May 28, 2016
1 parent 05fa158 commit cbc699f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,28 +1084,28 @@ namespace Sass {

}

Selector_List* Selector_List::parentize(Selector_List* ps, Context& ctx)
Selector_List* Selector_List::parentize(Selector_List* ps, Context& ctx, bool implicit_parent = true)
{
if (!this->has_parent_ref()) return this;
Selector_List* ss = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
for (size_t pi = 0, pL = ps->length(); pi < pL; ++pi) {
Selector_List* list = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
*list << (*ps)[pi];
for (size_t si = 0, sL = this->length(); si < sL; ++si) {
*ss += (*this)[si]->parentize(list, ctx);
*ss += (*this)[si]->parentize(list, ctx, implicit_parent);
}
}
return ss;
}

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

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

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

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

Expand Down Expand Up @@ -1186,7 +1186,7 @@ namespace Sass {
for (Simple_Selector* ss : *head) {
if (Wrapped_Selector* ws = dynamic_cast<Wrapped_Selector*>(ss)) {
if (Selector_List* sl = dynamic_cast<Selector_List*>(ws->selector())) {
if (parents) ws->selector(sl->parentize(parents, ctx));
if (parents) ws->selector(sl->parentize(parents, ctx, implicit_parent));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2392,7 +2392,7 @@ namespace Sass {
Complex_Selector* innermost() { return last(); };

size_t length() const;
Selector_List* parentize(Selector_List* parents, Context& ctx);
Selector_List* parentize(Selector_List* parents, Context& ctx, bool implicit_parent = true);
virtual bool is_superselector_of(Compound_Selector* sub, std::string wrapping = "");
virtual bool is_superselector_of(Complex_Selector* sub, std::string wrapping = "");
virtual bool is_superselector_of(Selector_List* sub, std::string wrapping = "");
Expand Down Expand Up @@ -2505,7 +2505,7 @@ namespace Sass {
virtual bool has_parent_ref();
void remove_parent_selectors();
// virtual Selector_Placeholder* find_placeholder();
Selector_List* parentize(Selector_List* parents, Context& ctx);
Selector_List* parentize(Selector_List* parents, Context& ctx, bool implicit_parent);
virtual bool is_superselector_of(Compound_Selector* sub, std::string wrapping = "");
virtual bool is_superselector_of(Complex_Selector* sub, std::string wrapping = "");
virtual bool is_superselector_of(Selector_List* sub, std::string wrapping = "");
Expand Down
3 changes: 2 additions & 1 deletion src/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,8 @@ namespace Sass {

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

}

Expand Down
5 changes: 4 additions & 1 deletion src/expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ namespace Sass {
media_block_stack(std::vector<Media_Block*>()),
backtrace_stack(std::vector<Backtrace*>()),
in_keyframes(false),
at_root_without_rule(false)
at_root_without_rule(false),
old_at_root_without_rule(false)
{
env_stack.push_back(0);
env_stack.push_back(env);
Expand Down Expand Up @@ -87,6 +88,8 @@ namespace Sass {

Statement* Expand::operator()(Ruleset* r)
{
LOCAL_FLAG(old_at_root_without_rule, at_root_without_rule);

if (in_keyframes) {
Keyframe_Rule* k = SASS_MEMORY_NEW(ctx.mem, Keyframe_Rule, r->pstate(), r->block()->perform(this)->block());
if (r->selector()) {
Expand Down
1 change: 1 addition & 0 deletions src/expand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Sass {
std::vector<Backtrace*> backtrace_stack;
bool in_keyframes;
bool at_root_without_rule;
bool old_at_root_without_rule;

Statement* fallback_impl(AST_Node* n);

Expand Down
2 changes: 1 addition & 1 deletion src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,7 @@ namespace Sass {
for(;itr != parsedSelectors.end(); ++itr) {
Selector_List* child = *itr;
std::vector<Complex_Selector*> exploded;
Selector_List* rv = child->parentize(result, ctx);
Selector_List* rv = child->parentize(result, ctx, true);
for (size_t m = 0, mLen = rv->length(); m < mLen; ++m) {
exploded.push_back((*rv)[m]);
}
Expand Down

0 comments on commit cbc699f

Please sign in to comment.