Skip to content

Commit e87c8a1

Browse files
committed
Improve parent selector handling in selector schema (#2358)
1 parent 39cbc08 commit e87c8a1

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);
@@ -1757,7 +1758,10 @@ namespace Sass {
17571758
Selector_List_Ptr Eval::operator()(Complex_Selector_Ptr s)
17581759
{
17591760
bool implicit_parent = !exp.old_at_root_without_rule;
1760-
return s->resolve_parent_refs(exp.selector_stack, implicit_parent);
1761+
if (is_in_selector_schema) exp.selector_stack.push_back(0);
1762+
Selector_List_Obj resolved = s->resolve_parent_refs(exp.selector_stack, implicit_parent);
1763+
if (is_in_selector_schema) exp.selector_stack.pop_back();
1764+
return resolved.detach();
17611765
}
17621766

17631767
// XXX: this is never hit via spec tests
@@ -1772,6 +1776,7 @@ namespace Sass {
17721776

17731777
Selector_List_Ptr Eval::operator()(Selector_Schema_Ptr s)
17741778
{
1779+
LOCAL_FLAG(is_in_selector_schema, true);
17751780
// the parser will look for a brace to end the selector
17761781
Expression_Obj sel = s->contents()->perform(this);
17771782
std::string result_str(sel->to_string(ctx.c_options));
@@ -1781,6 +1786,7 @@ namespace Sass {
17811786
// a selector schema may or may not connect to parent?
17821787
bool chroot = s->connect_parent() == false;
17831788
Selector_List_Obj sl = p.parse_selector_list(chroot);
1789+
flag_is_in_selector_schema.reset();
17841790
return operator()(sl);
17851791
}
17861792

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)