Skip to content

Commit

Permalink
Merge pull request #1193 from mgreter/bugfix/issue_1192
Browse files Browse the repository at this point in the history
Improve keyword handling in arglists
  • Loading branch information
xzyfer committed May 11, 2015
2 parents fb82f0b + 167f2a8 commit fb33a2a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
12 changes: 12 additions & 0 deletions ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,18 @@ namespace Sass {
return operator==(&rhs);
}

size_t List::size() const {
if (!is_arglist_) return length();
// arglist expects a list of arguments
// so we need to break before keywords
for (size_t i = 0, L = length(); i < L; ++i) {
if (Argument* arg = dynamic_cast<Argument*>((*this)[i])) {
if (!arg->name().empty()) return i;
}
}
return length();
}

Expression* Hashed::at(Expression* k) const
{
if (elements_.count(k))
Expand Down
1 change: 1 addition & 0 deletions ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ namespace Sass {
bool is_invisible() { return !length(); }
Expression* value_at_index(size_t i);

virtual size_t size() const;
virtual bool operator==(Expression& rhs) const;
virtual bool operator==(Expression* rhs) const;

Expand Down
8 changes: 7 additions & 1 deletion bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ namespace Sass {
(*arglist) << new (ctx.mem) Argument(key->pstate(),
argmap->at(key),
name,
false,
false);
}

Expand All @@ -111,6 +112,7 @@ namespace Sass {
(*arglist) << new (ctx.mem) Argument(a->pstate(),
a->value(),
a->name(),
false,
false);
// check if we have rest argument
if (a->is_rest_argument()) {
Expand Down Expand Up @@ -144,7 +146,11 @@ namespace Sass {
a = static_cast<Argument*>((*arglist)[0]);
} else {
Expression* a_to_convert = (*arglist)[0];
a = new (ctx.mem) Argument(a_to_convert->pstate(), a_to_convert, "", false);
a = new (ctx.mem) Argument(a_to_convert->pstate(),
a_to_convert,
"",
false,
false);
}
arglist->elements().erase(arglist->elements().begin());
if (!arglist->length() || (!arglist->is_arglist() && ip + 1 == LP)) {
Expand Down
4 changes: 3 additions & 1 deletion debugger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
} else if (dynamic_cast<Mixin_Call*>(node)) {
Mixin_Call* block = dynamic_cast<Mixin_Call*>(node);
cerr << ind << "Mixin_Call " << block << " " << block->tabs() << endl;
cerr << ind << "Mixin_Call " << block << " " << block->tabs();
cerr << " [" << block->name() << "]" << endl;
debug_ast(block->arguments(), ind + " args: ");
if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
} else if (dynamic_cast<Ruleset*>(node)) {
Ruleset* ruleset = dynamic_cast<Ruleset*>(node);
Expand Down
14 changes: 7 additions & 7 deletions functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ namespace Sass {

List* list = dynamic_cast<List*>(env["$list"]);
return new (ctx.mem) Number(pstate,
list ? list->length() : 1);
list ? list->size() : 1);
}

Signature nth_sig = "nth($list, $n)";
Expand Down Expand Up @@ -1356,13 +1356,10 @@ namespace Sass {
{
List* arglist = new (ctx.mem) List(*ARG("$args", List));
Map* result = new (ctx.mem) Map(pstate, 1);
// The parser ensures the ordering of arguments so we can assert this
// isn't keyword argument list the first argument isn't a keyword argument
if (!(arglist->empty() || ((Argument*)(*arglist)[0])->is_keyword_argument())) return result;
for (size_t i = 0, L = arglist->length(); i < L; ++i) {
for (size_t i = arglist->size(), L = arglist->length(); i < L; ++i) {
string name = string(((Argument*)(*arglist)[i])->name());
string sanitized_name = string(name, 1);
*result << make_pair(new (ctx.mem) String_Constant(pstate, sanitized_name),
name = name.erase(0, 1); // sanitize name (remove dollar sign)
*result << make_pair(new (ctx.mem) String_Constant(pstate, name),
((Argument*)(*arglist)[i])->value());
}
return result;
Expand Down Expand Up @@ -1551,11 +1548,14 @@ namespace Sass {
} else if (v->concrete_type() == Expression::STRING) {
return v;
} else {
bool parentheses = v->concrete_type() == Expression::MAP ||
v->concrete_type() == Expression::LIST;
Output_Style old_style;
old_style = ctx.output_style;
ctx.output_style = NESTED;
To_String to_string(&ctx, false);
string inspect = v->perform(&to_string);
if (inspect.empty() && parentheses) inspect = "()";
ctx.output_style = old_style;
return new (ctx.mem) String_Constant(pstate, inspect);

Expand Down
2 changes: 1 addition & 1 deletion inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ namespace Sass {
if (list->separator() == List::SPACE) in_space_array = true;
else if (list->separator() == List::COMMA) in_comma_array = true;

for (size_t i = 0, L = list->length(); i < L; ++i) {
for (size_t i = 0, L = list->size(); i < L; ++i) {
Expression* list_item = (*list)[i];
if (list_item->is_invisible()) {
continue;
Expand Down

0 comments on commit fb33a2a

Please sign in to comment.