Skip to content

Commit

Permalink
Merge pull request #1986 from mgreter/bugfix/issue_1417
Browse files Browse the repository at this point in the history
Patch division delay (keep slash) with function calls
  • Loading branch information
xzyfer committed Apr 10, 2016
2 parents 56e96a8 + d2b3db1 commit c624d6e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
23 changes: 23 additions & 0 deletions src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,29 @@ namespace Sass {
return is_interpolant() || (right() && right()->is_right_interpolant());
}

// delay binary expressions in function arguments
// https://github.com/sass/libsass/issues/1417
bool Binary_Expression::can_delay(void) const
{
bool l_delay = false;
bool r_delay = false;
if (op().operand == Sass_OP::DIV) {
if (Textual* tl = dynamic_cast<Textual*>(left())) {
l_delay = tl->type() == Textual::NUMBER ||
tl->type() == Textual::DIMENSION;
} else {
l_delay = dynamic_cast<Number*>(left()) != NULL;
}
if (Textual* tr = dynamic_cast<Textual*>(right())) {
r_delay = tr->type() == Textual::NUMBER ||
tr->type() == Textual::DIMENSION;
} else {
r_delay = dynamic_cast<Number*>(right()) != NULL;
}
}
return l_delay && r_delay;
}

std::string AST_Node::to_string(Sass_Inspect_Options opt) const
{
Sass_Output_Options out(opt);
Expand Down
6 changes: 6 additions & 0 deletions src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,12 @@ namespace Sass {
return is_left_interpolant() ||
is_right_interpolant();
}
virtual bool can_delay() const;
void reset_whitespace()
{
op_.ws_before = false;
op_.ws_after = false;
}
virtual void set_delayed(bool delayed)
{
right()->set_delayed(delayed);
Expand Down
28 changes: 25 additions & 3 deletions src/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,17 +832,34 @@ namespace Sass {
stm << "Stack depth exceeded max of " << Constants::MaxCallStack;
error(stm.str(), c->pstate(), backtrace());
}

std::string name(Util::normalize_underscores(c->name()));
std::string full_name(name + "[f]");
Arguments* args = c->arguments();
if (full_name != "if[f]") {
args = static_cast<Arguments*>(args->perform(this));

// handle call here if valid arg
// otherwise we eval arguments to early
if (name == "call" && args->length() > 0) {
Expression* redirect = args->at(0)->perform(this);
args->erase(args->begin());
Function_Call* lit = SASS_MEMORY_NEW(ctx.mem, Function_Call,
c->pstate(),
unquote(redirect->to_string()),
args);
return operator()(lit);
}

Env* env = environment();
if (!env->has(full_name)) {
if (!env->has("*[f]")) {
// just pass it through as a literal
for (Argument* arg : *args) {
if (Binary_Expression* b = dynamic_cast<Binary_Expression*>(arg->value())) {
b->reset_whitespace();
arg->is_delayed(b->can_delay()); // delay
}
}
args = static_cast<Arguments*>(args->perform(this));
Function_Call* lit = SASS_MEMORY_NEW(ctx.mem, Function_Call,
c->pstate(),
c->name(),
Expand All @@ -861,6 +878,10 @@ namespace Sass {
}
}

if (full_name != "if[f]") {
args = static_cast<Arguments*>(args->perform(this));
}

Definition* def = static_cast<Definition*>((*env)[full_name]);

if (def->is_overload_stub()) {
Expand Down Expand Up @@ -1321,7 +1342,8 @@ namespace Sass {
Expression* Eval::operator()(Argument* a)
{
Expression* val = a->value();
val->is_delayed(false);
// delay missin function arguments?
val->is_delayed(a->is_delayed());
val = val->perform(this);
val->is_delayed(false);

Expand Down

0 comments on commit c624d6e

Please sign in to comment.