Commit bd9aba84 by Aaron Leung

Updating the 'compact' built-in so that it works correctly with the newer definition style.

parent 322edca1
...@@ -933,29 +933,33 @@ namespace Sass { ...@@ -933,29 +933,33 @@ namespace Sass {
extern Signature compact_sig = "compact($arg1: false, $arg2: false, $arg3: false, $arg4: false, $arg5: false, $arg6: false, $arg7: false, $arg8: false, $arg9: false, $arg10: false, $arg11: false, $arg12: false)"; extern Signature compact_sig = "compact($arg1: false, $arg2: false, $arg3: false, $arg4: false, $arg5: false, $arg6: false, $arg7: false, $arg8: false, $arg9: false, $arg10: false, $arg11: false, $arg12: false)";
Node compact(const Node parameter_names, Environment& bindings, Node_Factory& new_Node, string& path, size_t line) { Node compact(const Node parameter_names, Environment& bindings, Node_Factory& new_Node, string& path, size_t line) {
size_t num_args = bindings.current_frame.size(); Node first_arg(bindings[parameter_names[0].token()]);
Node::Type sep_type = Node::comma_list; Node rest_args(new_Node(Node::comma_list, path, line, 0));
Node list; for (size_t i = 1, S = bindings.current_frame.size(); i < S; ++i) {
Node arg1(bindings[parameter_names[0].token()]); Node the_arg(bindings[parameter_names[i].token()]);
if (num_args == 1 && (arg1.type() == Node::space_list || if (!the_arg.is_false()) rest_args << new_Node(path, line, the_arg);
arg1.type() == Node::comma_list || }
arg1.type() == Node::nil)) { if (rest_args.size() > 0) {
list = new_Node(arg1.type(), path, line, arg1.size()); Node result(new_Node(Node::comma_list, path, line, rest_args.size() + (first_arg.is_false() ? 0 : 1)));
list += arg1; if (!first_arg.is_false()) result << new_Node(path, line, first_arg);
result += rest_args;
return result;
} }
else { else {
list = new_Node(sep_type, arg1.path(), arg1.line(), num_args); Node::Type first_type = first_arg.type();
for (size_t i = 0; i < num_args; ++i) { if (first_type == Node::space_list || first_type == Node::comma_list) {
list << bindings[parameter_names[i].token()]; Node result(new_Node(first_type, path, line, 0));
for (size_t i = 0, S = first_arg.size(); i < S; ++i) {
if (!first_arg[i].is_false()) result << new_Node(path, line, first_arg[i]);
}
return result;
} }
} else {
Node new_list(new_Node(list.type(), list.path(), list.line(), 0)); return new_Node(path, line, first_arg);
for (size_t i = 0, S = list.size(); i < S; ++i) {
if ((list[i].type() != Node::boolean) || list[i].boolean_value()) {
new_list << list[i];
} }
} }
return new_list.size() ? new_list : new_Node(Node::nil, path, line, 0); // unreachable
return Node();
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
......
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