Skip to content

Commit fb33a2a

Browse files
committed
Merge pull request #1193 from mgreter/bugfix/issue_1192
Improve keyword handling in arglists
2 parents fb82f0b + 167f2a8 commit fb33a2a

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

ast.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,18 @@ namespace Sass {
856856
return operator==(&rhs);
857857
}
858858

859+
size_t List::size() const {
860+
if (!is_arglist_) return length();
861+
// arglist expects a list of arguments
862+
// so we need to break before keywords
863+
for (size_t i = 0, L = length(); i < L; ++i) {
864+
if (Argument* arg = dynamic_cast<Argument*>((*this)[i])) {
865+
if (!arg->name().empty()) return i;
866+
}
867+
}
868+
return length();
869+
}
870+
859871
Expression* Hashed::at(Expression* k) const
860872
{
861873
if (elements_.count(k))

ast.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ namespace Sass {
757757
bool is_invisible() { return !length(); }
758758
Expression* value_at_index(size_t i);
759759

760+
virtual size_t size() const;
760761
virtual bool operator==(Expression& rhs) const;
761762
virtual bool operator==(Expression* rhs) const;
762763

bind.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ namespace Sass {
9393
(*arglist) << new (ctx.mem) Argument(key->pstate(),
9494
argmap->at(key),
9595
name,
96+
false,
9697
false);
9798
}
9899

@@ -111,6 +112,7 @@ namespace Sass {
111112
(*arglist) << new (ctx.mem) Argument(a->pstate(),
112113
a->value(),
113114
a->name(),
115+
false,
114116
false);
115117
// check if we have rest argument
116118
if (a->is_rest_argument()) {
@@ -144,7 +146,11 @@ namespace Sass {
144146
a = static_cast<Argument*>((*arglist)[0]);
145147
} else {
146148
Expression* a_to_convert = (*arglist)[0];
147-
a = new (ctx.mem) Argument(a_to_convert->pstate(), a_to_convert, "", false);
149+
a = new (ctx.mem) Argument(a_to_convert->pstate(),
150+
a_to_convert,
151+
"",
152+
false,
153+
false);
148154
}
149155
arglist->elements().erase(arglist->elements().begin());
150156
if (!arglist->length() || (!arglist->is_arglist() && ip + 1 == LP)) {

debugger.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
356356
if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
357357
} else if (dynamic_cast<Mixin_Call*>(node)) {
358358
Mixin_Call* block = dynamic_cast<Mixin_Call*>(node);
359-
cerr << ind << "Mixin_Call " << block << " " << block->tabs() << endl;
359+
cerr << ind << "Mixin_Call " << block << " " << block->tabs();
360+
cerr << " [" << block->name() << "]" << endl;
361+
debug_ast(block->arguments(), ind + " args: ");
360362
if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
361363
} else if (dynamic_cast<Ruleset*>(node)) {
362364
Ruleset* ruleset = dynamic_cast<Ruleset*>(node);

functions.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ namespace Sass {
11071107

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

11131113
Signature nth_sig = "nth($list, $n)";
@@ -1356,13 +1356,10 @@ namespace Sass {
13561356
{
13571357
List* arglist = new (ctx.mem) List(*ARG("$args", List));
13581358
Map* result = new (ctx.mem) Map(pstate, 1);
1359-
// The parser ensures the ordering of arguments so we can assert this
1360-
// isn't keyword argument list the first argument isn't a keyword argument
1361-
if (!(arglist->empty() || ((Argument*)(*arglist)[0])->is_keyword_argument())) return result;
1362-
for (size_t i = 0, L = arglist->length(); i < L; ++i) {
1359+
for (size_t i = arglist->size(), L = arglist->length(); i < L; ++i) {
13631360
string name = string(((Argument*)(*arglist)[i])->name());
1364-
string sanitized_name = string(name, 1);
1365-
*result << make_pair(new (ctx.mem) String_Constant(pstate, sanitized_name),
1361+
name = name.erase(0, 1); // sanitize name (remove dollar sign)
1362+
*result << make_pair(new (ctx.mem) String_Constant(pstate, name),
13661363
((Argument*)(*arglist)[i])->value());
13671364
}
13681365
return result;
@@ -1551,11 +1548,14 @@ namespace Sass {
15511548
} else if (v->concrete_type() == Expression::STRING) {
15521549
return v;
15531550
} else {
1551+
bool parentheses = v->concrete_type() == Expression::MAP ||
1552+
v->concrete_type() == Expression::LIST;
15541553
Output_Style old_style;
15551554
old_style = ctx.output_style;
15561555
ctx.output_style = NESTED;
15571556
To_String to_string(&ctx, false);
15581557
string inspect = v->perform(&to_string);
1558+
if (inspect.empty() && parentheses) inspect = "()";
15591559
ctx.output_style = old_style;
15601560
return new (ctx.mem) String_Constant(pstate, inspect);
15611561

inspect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ namespace Sass {
362362
if (list->separator() == List::SPACE) in_space_array = true;
363363
else if (list->separator() == List::COMMA) in_comma_array = true;
364364

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

0 commit comments

Comments
 (0)