Commit 2bc7b366 by Aaron Leung

Converting 'unit' builtin.

parent a187103d
...@@ -878,17 +878,18 @@ namespace Sass { ...@@ -878,17 +878,18 @@ namespace Sass {
size_t size = 0; size_t size = 0;
if (l1.type() != Node::nil) size += l1.size(); if (l1.type() != Node::nil) size += l1.size();
if (l2.type() != Node::nil) size += l2.size(); if (l2.type() != Node::nil) size += l2.size();
// figure out the result type in advance // figure out the result type in advance
Node::Type rtype = Node::space_list; Node::Type rtype = Node::space_list;
string sep(bindings[parameter_names[2].token()].token().unquote()); string sep(bindings[parameter_names[2].token()].token().unquote());
if (sep == "comma") rtype = Node::comma_list; if (sep == "comma") rtype = Node::comma_list;
else if (sep == "space") rtype = Node::space_list; else if (sep == "space") rtype = Node::space_list;
else if (sep == "auto") rtype = l1.type(); else if (sep == "auto") rtype = l1.type();
else { else {
throw_eval_error("third argument to join must be 'space', 'comma', or 'auto'", path, line); throw_eval_error("third argument to 'join' must be 'space', 'comma', or 'auto'", path, line);
} }
if (rtype == Node::nil) rtype = l2.type(); if (rtype == Node::nil) rtype = l2.type();
// accumulate the result // accumulate the result
Node lr(new_Node(rtype, path, line, size)); Node lr(new_Node(rtype, path, line, size));
if (l1.type() != Node::nil) lr += l1; if (l1.type() != Node::nil) lr += l1;
...@@ -917,7 +918,7 @@ namespace Sass { ...@@ -917,7 +918,7 @@ namespace Sass {
if (sep_string == "comma") sep_type = Node::comma_list; if (sep_string == "comma") sep_type = Node::comma_list;
else if (sep_string == "space") sep_type = Node::space_list; else if (sep_string == "space") sep_type = Node::space_list;
else if (sep_string == "auto") sep_type = list.type(); else if (sep_string == "auto") sep_type = list.type();
else throw_eval_error("third argument to append must be 'space', 'comma', or 'auto'", path, line); else throw_eval_error("third argument to 'append' must be 'space', 'comma', or 'auto'", path, line);
Node new_list(new_Node(sep_type, path, line, list.size() + 1)); Node new_list(new_Node(sep_type, path, line, list.size() + 1));
new_list += list; new_list += list;
...@@ -997,7 +998,7 @@ namespace Sass { ...@@ -997,7 +998,7 @@ namespace Sass {
extern Signature unit_sig = "unit($number)"; extern Signature unit_sig = "unit($number)";
Node unit(const Node parameter_names, Environment& bindings, Node_Factory& new_Node, string& path, size_t line) { Node unit(const Node parameter_names, Environment& bindings, Node_Factory& new_Node, string& path, size_t line) {
Node val(bindings[parameter_names[0].token()]); Node val(arg(unit_sig, path, line, parameter_names, bindings, 0, Node::numeric));
switch (val.type()) switch (val.type())
{ {
case Node::number: { case Node::number: {
...@@ -1009,6 +1010,7 @@ namespace Sass { ...@@ -1009,6 +1010,7 @@ namespace Sass {
return new_Node(Node::string_constant, path, line, val.unit()); return new_Node(Node::string_constant, path, line, val.unit());
} break; } break;
// unreachable
default: { default: {
throw_eval_error("argument to unit must be numeric", path, line); throw_eval_error("argument to unit must be numeric", path, line);
} break; } break;
......
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