Skip to content

Commit

Permalink
Merge pull request #2127 from mgreter/bugfix/issue-2124
Browse files Browse the repository at this point in the history
Pass selector stack when calling functions
  • Loading branch information
mgreter authored Jul 20, 2016
2 parents 7a455d1 + 2f42bd5 commit 6610e81
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ namespace Sass {
struct Backtrace;
typedef Environment<AST_Node*> Env;
typedef const char* Signature;
typedef Expression* (*Native_Function)(Env&, Env&, Context&, Signature, ParserState, Backtrace*);
typedef Expression* (*Native_Function)(Env&, Env&, Context&, Signature, ParserState, Backtrace*, std::vector<CommaSequence_Selector*>);
typedef const char* Signature;
class Definition : public Has_Block {
public:
Expand Down
2 changes: 1 addition & 1 deletion src/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ namespace Sass {
exp.backtrace_stack.push_back(&here);
// eval the body if user-defined or special, invoke underlying CPP function if native
if (body && !Prelexer::re_special_fun(name.c_str())) { result = body->perform(this); }
else if (func) { result = func(fn_env, *env, ctx, def->signature(), c->pstate(), backtrace()); }
else if (func) { result = func(fn_env, *env, ctx, def->signature(), c->pstate(), backtrace(), exp.selector_stack); }
if (!result) error(std::string("Function ") + c->name() + " did not return a value", c->pstate());
exp.backtrace_stack.pop_back();
}
Expand Down
5 changes: 3 additions & 2 deletions src/expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Sass {

Expand::Expand(Context& ctx, Env* env, Backtrace* bt)
Expand::Expand(Context& ctx, Env* env, Backtrace* bt, std::vector<CommaSequence_Selector*>* stack)
: ctx(ctx),
eval(Eval(*this)),
env_stack(std::vector<Env*>()),
Expand All @@ -31,7 +31,8 @@ namespace Sass {
call_stack.push_back(0);
// import_stack.push_back(0);
property_stack.push_back(0);
selector_stack.push_back(0);
if (stack == NULL) { selector_stack.push_back(0); }
else { selector_stack.insert(selector_stack.end(), stack->begin(), stack->end()); }
media_block_stack.push_back(0);
backtrace_stack.push_back(0);
backtrace_stack.push_back(bt);
Expand Down
2 changes: 1 addition & 1 deletion src/expand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace Sass {
void expand_selector_list(Selector*, CommaSequence_Selector* extender);

public:
Expand(Context&, Env*, Backtrace*);
Expand(Context&, Env*, Backtrace*, std::vector<CommaSequence_Selector*>* stack = NULL);
~Expand() { }

Statement* operator()(Block*);
Expand Down
4 changes: 2 additions & 2 deletions src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ namespace Sass {
}
}
Function_Call* func = SASS_MEMORY_NEW(ctx.mem, Function_Call, pstate, name, args);
Expand expand(ctx, &d_env, backtrace);
Expand expand(ctx, &d_env, backtrace, &selector_stack);
return func->perform(&expand.eval);

}
Expand All @@ -1655,7 +1655,7 @@ namespace Sass {
// { return ARG("$condition", Expression)->is_false() ? ARG("$if-false", Expression) : ARG("$if-true", Expression); }
BUILT_IN(sass_if)
{
Expand expand(ctx, &d_env, backtrace);
Expand expand(ctx, &d_env, backtrace, &selector_stack);
bool is_true = !ARG("$condition", Expression)->perform(&expand.eval)->is_false();
Expression* res = ARG(is_true ? "$if-true" : "$if-false", Expression);
res = res->perform(&expand.eval);
Expand Down
4 changes: 2 additions & 2 deletions src/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "sass/functions.h"

#define BUILT_IN(name) Expression*\
name(Env& env, Env& d_env, Context& ctx, Signature sig, ParserState pstate, Backtrace* backtrace)
name(Env& env, Env& d_env, Context& ctx, Signature sig, ParserState pstate, Backtrace* backtrace, std::vector<CommaSequence_Selector*> selector_stack)

namespace Sass {
class Context;
Expand All @@ -17,7 +17,7 @@ namespace Sass {
class Definition;
typedef Environment<AST_Node*> Env;
typedef const char* Signature;
typedef Expression* (*Native_Function)(Env&, Env&, Context&, Signature, ParserState, Backtrace*);
typedef Expression* (*Native_Function)(Env&, Env&, Context&, Signature, ParserState, Backtrace*, std::vector<CommaSequence_Selector*>);

Definition* make_native_function(Signature, Native_Function, Context& ctx);
Definition* make_c_function(Sass_Function_Entry c_func, Context& ctx);
Expand Down

0 comments on commit 6610e81

Please # to comment.