Commit af2be372 by Aaron Leung

Correctly handling default arguments for mixins.

parent 23bc4ff1
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include "evaluator.hpp" #include "evaluator.hpp"
namespace Sass { namespace Sass {
void Document::eval_pending() void Document::eval_pending()
{ {
for (int i = 0; i < context.pending.size(); ++i) { for (int i = 0; i < context.pending.size(); ++i) {
...@@ -50,20 +49,33 @@ namespace Sass { ...@@ -50,20 +49,33 @@ namespace Sass {
n.children->pop_back(); n.children->pop_back();
Environment m_env; Environment m_env;
// bind arguments
for (int i = 0, j = 0; i < args.size(); ++i) { for (int i = 0, j = 0; i < args.size(); ++i) {
if (args[i].type == Node::assignment) { if (args[i].type == Node::assignment) {
Node arg(args[i]); Node arg(args[i]);
Token key(arg[0].token); Token name(arg[0].token);
if (!m_env.query(key)) { if (!m_env.query(name)) {
m_env[key] = eval(arg[1], context.global_env); m_env[name] = eval(arg[1], context.global_env);
} }
} }
else { else {
// TO DO: ensure (j < params.size()) // 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; ++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); m_env.link(context.global_env);
for (int i = 0; i < body.size(); ++i) { for (int i = 0; i < body.size(); ++i) {
...@@ -71,6 +83,7 @@ namespace Sass { ...@@ -71,6 +83,7 @@ namespace Sass {
} }
n += body; n += body;
// ideally say: n += apply(mixin, args, context.global_env);
} break; } break;
} }
} }
......
...@@ -17,6 +17,8 @@ a { ...@@ -17,6 +17,8 @@ a {
@include foo($y: kwd-y, $x: kwd-x); @include foo($y: kwd-y, $x: kwd-x);
goo: boo hoo; goo: boo hoo;
@include hux; @include hux;
@include bar(pug);
@include bar(pug, mug);
} }
......
...@@ -4,7 +4,9 @@ a { ...@@ -4,7 +4,9 @@ a {
hugabug: why eks; hugabug: why eks;
hugabug: kwd-y kwd-x; hugabug: kwd-y kwd-x;
goo: boo hoo; goo: boo hoo;
no: parameters here; } no: parameters here;
flugablug: pug flug glug;
flugablug: pug mug glug; }
div { div {
blah: blah from a variable blah; } 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