diff --git a/ast.hpp b/ast.hpp index 4a1819df95..59b9a4e83a 100644 --- a/ast.hpp +++ b/ast.hpp @@ -475,11 +475,11 @@ namespace Sass { // The Sass `@each` control directive. ////////////////////////////////////// class Each : public Has_Block { - ADD_PROPERTY(vector, variables); + ADD_PROPERTY(string, variable); ADD_PROPERTY(Expression*, list); public: - Each(string path, Position position, vector vars, Expression* lst, Block* b) - : Has_Block(path, position, b), variables_(vars), list_(lst) + Each(string path, Position position, string var, Expression* lst, Block* b) + : Has_Block(path, position, b), variable_(var), list_(lst) { } ATTACH_OPERATIONS(); }; diff --git a/ast_factory.hpp b/ast_factory.hpp index 2624d96c0a..7cb7ccc4e3 100644 --- a/ast_factory.hpp +++ b/ast_factory.hpp @@ -26,7 +26,7 @@ namespace Sass { Comment* new_Comment(string p, size_t l, String* txt); If* new_If(string p, size_t l, Expression* pred, Block* con, Block* alt = 0); For* new_For(string p, size_t l, string var, Expression* lo, Expression* hi, Block* b, bool inc); - Each* new_Each(string p, size_t l, vector vars, Expression* lst, Block* b); + Each* new_Each(string p, size_t l, string var, Expression* lst, Block* b); While* new_While(string p, size_t l, Expression* pred, Block* b); Extension* new_Extension(string p, size_t l, Selector* s); Definition* new_Mixin_Definition(string p, size_t l, string n, Parameters* params, Block* b); diff --git a/expand.cpp b/expand.cpp index 97afe51529..0aa1509412 100644 --- a/expand.cpp +++ b/expand.cpp @@ -211,14 +211,10 @@ namespace Sass { Statement* Expand::operator()(Each* e) { - vector variables(e->variables()); + string variable(e->variable()); Expression* expr = e->list()->perform(eval->with(env, backtrace)); List* list = 0; - Map* map = 0; - if (expr->concrete_type() == Expression::MAP) { - map = static_cast(expr); - } - else if (expr->concrete_type() != Expression::LIST) { + if (expr->concrete_type() != Expression::LIST) { list = new (ctx.mem) List(expr->path(), expr->position(), 1, List::COMMA); *list << expr; } @@ -226,31 +222,13 @@ namespace Sass { list = static_cast(expr); } Env new_env; - for (size_t i = 0, L = variables.size(); i < L; ++i) new_env[variables[i]] = 0; + new_env[variable] = 0; new_env.link(env); env = &new_env; Block* body = e->block(); - - if (map) { - for (auto key : map->keys()) { - (*env)[variables[0]] = key->perform(eval->with(env, backtrace)); - (*env)[variables[1]] = map->at(key)->perform(eval->with(env, backtrace)); - append_block(body); - } - } - else { - for (size_t i = 0, L = list->length(); i < L; ++i) { - List* variable = static_cast(list->value_at_index(i)); - for (size_t j = 0, K = variables.size(); j < K; ++j) { - if (j < variable->length()) { - (*env)[variables[j]] = (*variable)[j]->perform(eval->with(env, backtrace)); - } - else { - (*env)[variables[j]] = new (ctx.mem) Null(expr->path(), expr->position()); - } - } - append_block(body); - } + for (size_t i = 0, L = list->length(); i < L; ++i) { + (*env)[variable] = (*list)[i]->perform(eval->with(env, backtrace)); + append_block(body); } env = new_env.parent(); return 0; diff --git a/inspect.cpp b/inspect.cpp index 8e82e1374f..18f12d7f6c 100644 --- a/inspect.cpp +++ b/inspect.cpp @@ -162,11 +162,7 @@ namespace Sass { void Inspect::operator()(Each* loop) { append_to_buffer("@each "); - append_to_buffer(loop->variables()[0]); - for (size_t i = 1, L = loop->variables().size(); i < L; ++i) { - append_to_buffer(", "); - append_to_buffer(loop->variables()[i]); - } + append_to_buffer(loop->variable()); append_to_buffer(" in "); loop->list()->perform(this); loop->block()->perform(this); diff --git a/parser.cpp b/parser.cpp index b86b02c4d1..e177439b4a 100644 --- a/parser.cpp +++ b/parser.cpp @@ -1,6 +1,5 @@ #include #include -#include #include "parser.hpp" #include "file.hpp" #include "inspect.hpp" @@ -1455,12 +1454,7 @@ namespace Sass { lex < each_directive >(); Position each_source_position = source_position; if (!lex< variable >()) error("@each directive requires an iteration variable"); - vector vars; - vars.push_back(Util::normalize_underscores(lexed)); - while (peek< exactly<','> >() && lex< exactly<','> >()) { - if (!lex< variable >()) error("@each directive requires an iteration variable"); - vars.push_back(Util::normalize_underscores(lexed)); - } + string var(Util::normalize_underscores(lexed)); if (!lex< in >()) error("expected 'in' keyword in @each directive"); Expression* list = parse_list(); list->is_delayed(false); @@ -1472,7 +1466,7 @@ namespace Sass { } if (!peek< exactly<'{'> >()) error("expected '{' after the upper bound in @each directive"); Block* body = parse_block(); - return new (ctx.mem) Each(path, each_source_position, vars, list, body); + return new (ctx.mem) Each(path, each_source_position, var, list, body); } While* Parser::parse_while_directive()