Skip to content

Commit

Permalink
Improve at-root handling with mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Oct 19, 2015
1 parent aa4dbbf commit e384b6f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,10 @@ namespace Sass {
Compound_Selector* h = 0,
Complex_Selector* t = 0,
String* r = 0)
: Selector(pstate), combinator_(c), head_(h), tail_(t), reference_(r)
: Selector(pstate),
combinator_(c),
head_(h), tail_(t),
reference_(r)
{
if ((h && h->has_reference()) || (t && t->has_reference())) has_reference(true);
if ((h && h->has_placeholder()) || (t && t->has_placeholder())) has_placeholder(true);
Expand Down
7 changes: 6 additions & 1 deletion src/debugger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
std::cerr << " (" << pstate_source_position(node) << ")";
std::cerr << " " << root_block->tabs();
std::cerr << std::endl;
if (root_block->block()) for(auto i : root_block->block()->elements()) { debug_ast(i, ind + " ", env); }
debug_ast(root_block->expression(), ind + ":", env);
debug_ast(root_block->block(), ind + " ", env);
} else if (dynamic_cast<Selector_List*>(node)) {
Selector_List* selector = dynamic_cast<Selector_List*>(node);
std::cerr << ind << "Selector_List " << selector;
std::cerr << " (" << pstate_source_position(node) << ")";
std::cerr << " [@media:" << selector->media_block() << "]";
std::cerr << (selector->is_at_root() ? " [at-root]": " -");
std::cerr << (selector->is_optional() ? " [is_optional]": " -");
std::cerr << (selector->has_line_break() ? " [line-break]": " -");
std::cerr << (selector->has_line_feed() ? " [line-feed]": " -");
Expand All @@ -102,6 +104,7 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
<< " (" << pstate_source_position(node) << ")"
<< " [weight:" << longToHex(selector->specificity()) << "]"
<< " [@media:" << selector->media_block() << "]"
<< (selector->is_at_root() ? " [at-root]": " -")
<< (selector->is_optional() ? " [is_optional]": " -")
<< (selector->has_line_feed() ? " [line-feed]": " -")
<< (selector->has_line_break() ? " [line-break]": " -")
Expand Down Expand Up @@ -194,6 +197,7 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
<< " [@media:" << selector->media_block() << "]"
<< (selector->has_line_break() ? " [line-break]": " -")
<< (selector->has_line_feed() ? " [line-feed]": " -")
<< (selector->is_at_root() ? " [at-root]": " -")
<< std::endl;

debug_ast(selector->contents(), ind + " ");
Expand All @@ -205,6 +209,7 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
std::cerr << " (" << pstate_source_position(node) << ")";
std::cerr << (selector->has_line_break() ? " [line-break]": " -")
<< (selector->has_line_feed() ? " [line-feed]": " -")
<< (selector->is_at_root() ? " [at-root]": " -")
<< std::endl;

} else if (dynamic_cast<Media_Query_Expression*>(node)) {
Expand Down
10 changes: 9 additions & 1 deletion src/expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ namespace Sass {
r->pstate(),
sel,
blk);
// rr->selector()->is_at_root(true);
selector_stack.pop_back();
rr->tabs(r->tabs());

Expand Down Expand Up @@ -625,11 +626,18 @@ namespace Sass {
Env* env = environment();
// convert @content directives into mixin calls to the underlying thunk
if (!env->has("@content[m]")) return 0;
if (block_stack.back()->is_root()) {
selector_stack.push_back(0);
}
Mixin_Call* call = SASS_MEMORY_NEW(ctx.mem, Mixin_Call,
c->pstate(),
"@content",
SASS_MEMORY_NEW(ctx.mem, Arguments, c->pstate()));
return call->perform(this);
Statement* stm = call->perform(this);
if (block_stack.back()->is_root()) {
selector_stack.pop_back();
}
return stm;
}

// produce an error if something is not implemented
Expand Down

0 comments on commit e384b6f

Please sign in to comment.