Skip to content

Commit d121e7e

Browse files
authored
Merge pull request #2395 from mgreter/bugfix/issue-2358
Improve parent selector handling in selector schema (#2358)
2 parents df144b2 + 6bf1c20 commit d121e7e

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

src/ast_def_macros.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class LocalOption {
1919
this->orig = var;
2020
*(this->var) = orig;
2121
}
22+
void reset()
23+
{
24+
*(this->var) = this->orig;
25+
}
2226
~LocalOption() {
2327
*(this->var) = this->orig;
2428
}

src/debugger.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ inline void debug_ast(AST_Node_Ptr node, std::string ind, Env* env)
103103
std::cerr << (selector->has_line_break() ? " [line-break]": " -");
104104
std::cerr << (selector->has_line_feed() ? " [line-feed]": " -");
105105
std::cerr << std::endl;
106-
debug_ast(selector->schema(), "#{} ");
106+
debug_ast(selector->schema(), ind + "#{} ");
107107

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

src/eval.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ namespace Sass {
5151
: exp(exp),
5252
ctx(exp.ctx),
5353
force(false),
54-
is_in_comment(false)
54+
is_in_comment(false),
55+
is_in_selector_schema(false)
5556
{
5657
bool_true = SASS_MEMORY_NEW(Boolean, "[NA]", true);
5758
bool_false = SASS_MEMORY_NEW(Boolean, "[NA]", false);
@@ -1759,7 +1760,10 @@ namespace Sass {
17591760
Selector_List_Ptr Eval::operator()(Complex_Selector_Ptr s)
17601761
{
17611762
bool implicit_parent = !exp.old_at_root_without_rule;
1762-
return s->resolve_parent_refs(exp.selector_stack, implicit_parent);
1763+
if (is_in_selector_schema) exp.selector_stack.push_back(0);
1764+
Selector_List_Obj resolved = s->resolve_parent_refs(exp.selector_stack, implicit_parent);
1765+
if (is_in_selector_schema) exp.selector_stack.pop_back();
1766+
return resolved.detach();
17631767
}
17641768

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

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

src/eval.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace Sass {
2525

2626
bool force;
2727
bool is_in_comment;
28+
bool is_in_selector_schema;
2829

2930
Boolean_Obj bool_true;
3031
Boolean_Obj bool_false;

0 commit comments

Comments
 (0)