Skip to content

Commit

Permalink
Merge pull request #2395 from mgreter/bugfix/issue-2358
Browse files Browse the repository at this point in the history
Improve parent selector handling in selector schema (#2358)
  • Loading branch information
mgreter authored May 21, 2017
2 parents df144b2 + 6bf1c20 commit d121e7e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/ast_def_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class LocalOption {
this->orig = var;
*(this->var) = orig;
}
void reset()
{
*(this->var) = this->orig;
}
~LocalOption() {
*(this->var) = this->orig;
}
Expand Down
2 changes: 1 addition & 1 deletion src/debugger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ inline void debug_ast(AST_Node_Ptr node, std::string ind, Env* env)
std::cerr << (selector->has_line_break() ? " [line-break]": " -");
std::cerr << (selector->has_line_feed() ? " [line-feed]": " -");
std::cerr << std::endl;
debug_ast(selector->schema(), "#{} ");
debug_ast(selector->schema(), ind + "#{} ");

for(const Complex_Selector_Obj& i : selector->elements()) { debug_ast(i, ind + " ", env); }

Expand Down
10 changes: 8 additions & 2 deletions src/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ namespace Sass {
: exp(exp),
ctx(exp.ctx),
force(false),
is_in_comment(false)
is_in_comment(false),
is_in_selector_schema(false)
{
bool_true = SASS_MEMORY_NEW(Boolean, "[NA]", true);
bool_false = SASS_MEMORY_NEW(Boolean, "[NA]", false);
Expand Down Expand Up @@ -1759,7 +1760,10 @@ namespace Sass {
Selector_List_Ptr Eval::operator()(Complex_Selector_Ptr s)
{
bool implicit_parent = !exp.old_at_root_without_rule;
return s->resolve_parent_refs(exp.selector_stack, implicit_parent);
if (is_in_selector_schema) exp.selector_stack.push_back(0);
Selector_List_Obj resolved = s->resolve_parent_refs(exp.selector_stack, implicit_parent);
if (is_in_selector_schema) exp.selector_stack.pop_back();
return resolved.detach();
}

// XXX: this is never hit via spec tests
Expand All @@ -1774,6 +1778,7 @@ namespace Sass {

Selector_List_Ptr Eval::operator()(Selector_Schema_Ptr s)
{
LOCAL_FLAG(is_in_selector_schema, true);
// the parser will look for a brace to end the selector
Expression_Obj sel = s->contents()->perform(this);
std::string result_str(sel->to_string(ctx.c_options));
Expand All @@ -1783,6 +1788,7 @@ namespace Sass {
// a selector schema may or may not connect to parent?
bool chroot = s->connect_parent() == false;
Selector_List_Obj sl = p.parse_selector_list(chroot);
flag_is_in_selector_schema.reset();
return operator()(sl);
}

Expand Down
1 change: 1 addition & 0 deletions src/eval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Sass {

bool force;
bool is_in_comment;
bool is_in_selector_schema;

Boolean_Obj bool_true;
Boolean_Obj bool_false;
Expand Down

0 comments on commit d121e7e

Please sign in to comment.