Commit 23bc4ff1 by Aaron Leung

Bam, mixins with arguments (including keyword args) are working properly.

parent 34638e5c
...@@ -12,6 +12,9 @@ namespace Sass { ...@@ -12,6 +12,9 @@ namespace Sass {
Environment(Environment* env) : frame(map<Token, Node>()), parent(env) Environment(Environment* env) : frame(map<Token, Node>()), parent(env)
{ } { }
void link(Environment& env)
{ parent = &env; }
bool query(const Token& key) const bool query(const Token& key) const
{ {
if (frame.count(key)) return true; if (frame.count(key)) return true;
......
...@@ -42,13 +42,34 @@ namespace Sass { ...@@ -42,13 +42,34 @@ namespace Sass {
case Node::expansion: { case Node::expansion: {
Token name(n[0].token); Token name(n[0].token);
Node args(n[1]); Node args(n[1]);
Node mixin(context.global_env[name]); Node mixin(context.global_env[name]);
Node params(mixin[1]); Node params(mixin[1]);
Node body(mixin[2].clone()); Node body(mixin[2].clone());
n.children->pop_back(); n.children->pop_back();
n.children->pop_back(); n.children->pop_back();
Environment m_env;
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);
}
}
else {
// TO DO: ensure (j < params.size())
m_env[params[j].token] = eval(args[i], context.global_env);
++j;
}
}
m_env.link(context.global_env);
for (int i = 0; i < body.size(); ++i) {
body[i] = eval(body[i], m_env);
}
n += body; n += body;
} break; } break;
} }
......
...@@ -9,6 +9,19 @@ namespace Sass { ...@@ -9,6 +9,19 @@ namespace Sass {
{ {
switch (expr.type) switch (expr.type)
{ {
case Node::rule: {
Node rhs(expr[1]);
if (rhs.type == Node::comma_list || rhs.type == Node::space_list) {
for (int i = 0; i < rhs.size(); ++i) {
if (rhs[i].eval_me) rhs[i] = eval(rhs[i], env);
}
}
else {
expr[1] = eval(rhs, env);
}
return expr;
} break;
case Node::comma_list: case Node::comma_list:
case Node::space_list: { case Node::space_list: {
if (expr.eval_me) { if (expr.eval_me) {
......
@mixin foo($x, $y) {
hugabug: $y $x;
}
@mixin bar($a, $b: flug) {
flugablug: $a $b glug;
}
@mixin hux() {
no: parameters here;
}
a {
hey: ho;
@include foo($x: kwd-arg another-kwd-arg, second, third);
@include foo(eks, why, $x: kwd-eks);
@include foo($y: kwd-y, $x: kwd-x);
goo: boo hoo;
@include hux;
}
$x: from a variable;
div {
blah: blah $x blah;
}
\ No newline at end of file
a {
hey: ho;
hugabug: third second;
hugabug: why eks;
hugabug: kwd-y kwd-x;
goo: boo hoo;
no: parameters here; }
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