Commit af2be372 by Aaron Leung

Correctly handling default arguments for mixins.

parent 23bc4ff1
......@@ -2,7 +2,6 @@
#include "evaluator.hpp"
namespace Sass {
void Document::eval_pending()
{
for (int i = 0; i < context.pending.size(); ++i) {
......@@ -50,20 +49,33 @@ namespace Sass {
n.children->pop_back();
Environment m_env;
// bind arguments
for (int i = 0, j = 0; i < args.size(); ++i) {
if (args[i].type == Node::assignment) {
Node arg(args[i]);
Token key(arg[0].token);
if (!m_env.query(key)) {
m_env[key] = eval(arg[1], context.global_env);
Token name(arg[0].token);
if (!m_env.query(name)) {
m_env[name] = eval(arg[1], context.global_env);
}
}
else {
// TO DO: ensure (j < params.size())
m_env[params[j].token] = eval(args[i], context.global_env);
Node param(params[j]);
Token name(param.type == Node::variable ? param.token : param[0].token);
m_env[name] = eval(args[i], context.global_env);
++j;
}
}
// plug the holes with default arguments if any
for (int i = 0; i < params.size(); ++i) {
if (params[i].type == Node::assignment) {
Node param(params[i]);
Token name(param[0].token);
if (!m_env.query(name)) {
m_env[name] = eval(param[1], context.global_env);
}
}
}
m_env.link(context.global_env);
for (int i = 0; i < body.size(); ++i) {
......@@ -71,6 +83,7 @@ namespace Sass {
}
n += body;
// ideally say: n += apply(mixin, args, context.global_env);
} break;
}
}
......
......@@ -17,6 +17,8 @@ a {
@include foo($y: kwd-y, $x: kwd-x);
goo: boo hoo;
@include hux;
@include bar(pug);
@include bar(pug, mug);
}
......
......@@ -4,7 +4,9 @@ a {
hugabug: why eks;
hugabug: kwd-y kwd-x;
goo: boo hoo;
no: parameters here; }
no: parameters here;
flugablug: pug flug glug;
flugablug: pug mug glug; }
div {
blah: blah from a variable blah; }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment