Skip to content

Commit

Permalink
Fix check for wrong import directives placement
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Jan 11, 2016
1 parent c13dfc0 commit 0e9279c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Sass {
eval(Eval(*this)),
env_stack(std::vector<Env*>()),
block_stack(std::vector<Block*>()),
call_stack(std::vector<AST_Node*>()),
property_stack(std::vector<String*>()),
selector_stack(std::vector<Selector_List*>()),
backtrace_stack(std::vector<Backtrace*>()),
Expand All @@ -28,6 +29,7 @@ namespace Sass {
env_stack.push_back(0);
env_stack.push_back(env);
block_stack.push_back(0);
call_stack.push_back(0);
// import_stack.push_back(0);
property_stack.push_back(0);
selector_stack.push_back(0);
Expand Down Expand Up @@ -327,6 +329,11 @@ namespace Sass {

Statement* Expand::operator()(Import_Stub* i)
{
// get parent node from call stack
AST_Node* parent = call_stack.back();
if (parent && dynamic_cast<Block*>(parent) == NULL) {
error("Import directives may not be used within control directives or mixins.", i->pstate());
}
// we don't seem to need that actually afterall
Sass_Import_Entry import = sass_make_import(
i->imp_path().c_str(),
Expand Down Expand Up @@ -372,13 +379,15 @@ namespace Sass {
{
Env env(environment(), true);
env_stack.push_back(&env);
call_stack.push_back(i);
if (*i->predicate()->perform(&eval)) {
append_block(i->block());
}
else {
Block* alt = i->alternative();
if (alt) append_block(alt);
}
call_stack.pop_back();
env_stack.pop_back();
return 0;
}
Expand Down Expand Up @@ -410,6 +419,7 @@ namespace Sass {
// only create iterator once in this environment
Env env(environment(), true);
env_stack.push_back(&env);
call_stack.push_back(f);
Number* it = SASS_MEMORY_NEW(env.mem, Number, low->pstate(), start, sass_end->unit());
env.set_local(variable, it);
Block* body = f->block();
Expand All @@ -432,6 +442,7 @@ namespace Sass {
append_block(body);
}
}
call_stack.pop_back();
env_stack.pop_back();
return 0;
}
Expand All @@ -457,6 +468,7 @@ namespace Sass {
// remember variables and then reset them
Env env(environment(), true);
env_stack.push_back(&env);
call_stack.push_back(e);
Block* body = e->block();

if (map) {
Expand Down Expand Up @@ -511,6 +523,7 @@ namespace Sass {
append_block(body);
}
}
call_stack.pop_back();
env_stack.pop_back();
return 0;
}
Expand All @@ -521,9 +534,11 @@ namespace Sass {
Block* body = w->block();
Env env(environment(), true);
env_stack.push_back(&env);
call_stack.push_back(w);
while (*pred->perform(&eval)) {
append_block(body);
}
call_stack.pop_back();
env_stack.pop_back();
return 0;
}
Expand Down Expand Up @@ -693,10 +708,12 @@ namespace Sass {
// process and add to last block on stack
inline void Expand::append_block(Block* b)
{
if (b->is_root()) call_stack.push_back(b);
for (size_t i = 0, L = b->length(); i < L; ++i) {
Statement* ith = (*b)[i]->perform(this);
if (ith) *block_stack.back() << ith;
}
if (b->is_root()) call_stack.pop_back();
}

}
1 change: 1 addition & 0 deletions src/expand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace Sass {
// it's easier to work with vectors
std::vector<Env*> env_stack;
std::vector<Block*> block_stack;
std::vector<AST_Node*> call_stack;
std::vector<String*> property_stack;
std::vector<Selector_List*> selector_stack;
std::vector<Backtrace*>backtrace_stack;
Expand Down
2 changes: 1 addition & 1 deletion src/operation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Sass {
virtual T operator()(Ruleset* x) = 0;
virtual T operator()(Propset* x) = 0;
virtual T operator()(Bubble* x) = 0;
virtual T operator()(Supports_Block* x) = 0;
virtual T operator()(Supports_Block* x) = 0;
virtual T operator()(Media_Block* x) = 0;
virtual T operator()(At_Root_Block* x) = 0;
virtual T operator()(At_Rule* x) = 0;
Expand Down
3 changes: 0 additions & 3 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ namespace Sass {

// parse imports to process later
else if (lex < kwd_import >(true)) {
if (stack.back() == mixin_def || stack.back() == function_def) {
error("Import directives may not be used within control directives or mixins.", pstate);
}
Import* imp = parse_import();
// if it is a url, we only add the statement
if (!imp->urls().empty()) (*block) << imp;
Expand Down

0 comments on commit 0e9279c

Please sign in to comment.