Skip to content

Commit a140623

Browse files
committed
Merge pull request #1135 from xzyfer/fix/issue-1133
Fix call function incorrectly expanding map arguments
2 parents f1c9e06 + 34f6053 commit a140623

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

bind.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ namespace Sass {
5656
else {
5757
env->local_frame()[p->name()] = a->value();
5858
}
59+
} else if (a->is_keyword_argument()) {
60+
61+
// expand keyword arguments into their parameters
62+
List* arglist = new (ctx.mem) List(p->pstate(), 0, List::COMMA, true);
63+
env->local_frame()[p->name()] = arglist;
64+
Map* argmap = static_cast<Map*>(a->value());
65+
for (auto key : argmap->keys()) {
66+
string name = unquote(static_cast<String_Constant*>(key)->value());
67+
(*arglist) << new (ctx.mem) Argument(key->pstate(),
68+
argmap->at(key),
69+
name,
70+
false);
71+
}
72+
5973
} else {
6074

6175
// copy all remaining arguments into the rest parameter, preserving names

debugger.hpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,12 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
342342
Definition* block = dynamic_cast<Definition*>(node);
343343
cerr << ind << "Definition " << block;
344344
cerr << " (" << pstate_source_position(node) << ")";
345+
cerr << " [name: " << block->name() << "] ";
346+
cerr << " [type: " << (block->type() == Sass::Definition::Type::MIXIN ? "Mixin " : "Function ") << "] ";
347+
cerr << " [signature: " << block->signature() << "] ";
348+
cerr << " [native: " << block->native_function() << "] ";
345349
cerr << " " << block->tabs() << endl;
350+
debug_ast(block->parameters(), ind + " params: ", env);
346351
if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
347352
} else if (dynamic_cast<Mixin_Call*>(node)) {
348353
Mixin_Call* block = dynamic_cast<Mixin_Call*>(node);
@@ -399,8 +404,26 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
399404
Argument* expression = dynamic_cast<Argument*>(node);
400405
cerr << ind << "Argument " << expression;
401406
cerr << " (" << pstate_source_position(node) << ")";
402-
cerr << " [" << expression->value() << "]" << endl;
407+
cerr << " [" << expression->value() << "]";
408+
cerr << " [name: " << expression->name() << "] ";
409+
cerr << " [rest: " << expression->is_rest_argument() << "] ";
410+
cerr << " [keyword: " << expression->is_keyword_argument() << "] " << endl;
403411
debug_ast(expression->value(), ind + " value: ", env);
412+
} else if (dynamic_cast<Parameters*>(node)) {
413+
Parameters* expression = dynamic_cast<Parameters*>(node);
414+
cerr << ind << "Parameters " << expression;
415+
cerr << " (" << pstate_source_position(node) << ")";
416+
cerr << " [has_optional: " << expression->has_optional_parameters() << "] ";
417+
cerr << " [has_rest: " << expression->has_rest_parameter() << "] ";
418+
cerr << endl;
419+
for(auto i : expression->elements()) { debug_ast(i, ind + " ", env); }
420+
} else if (dynamic_cast<Parameter*>(node)) {
421+
Parameter* expression = dynamic_cast<Parameter*>(node);
422+
cerr << ind << "Parameter " << expression;
423+
cerr << " (" << pstate_source_position(node) << ")";
424+
cerr << " [name: " << expression->name() << "] ";
425+
cerr << " [default: " << expression->default_value() << "] ";
426+
cerr << " [rest: " << expression->is_rest_parameter() << "] " << endl;
404427
} else if (dynamic_cast<Unary_Expression*>(node)) {
405428
Unary_Expression* expression = dynamic_cast<Unary_Expression*>(node);
406429
cerr << ind << "Unary_Expression " << expression;
@@ -427,6 +450,7 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
427450
(expression->separator() == Sass::List::Separator::COMMA ? "Comma " : "Space ") <<
428451
" [delayed: " << expression->is_delayed() << "] " <<
429452
" [interpolant: " << expression->is_interpolant() << "] " <<
453+
" [arglist: " << expression->is_arglist() << "] " <<
430454
endl;
431455
for(auto i : expression->elements()) { debug_ast(i, ind + " ", env); }
432456
} else if (dynamic_cast<Content*>(node)) {

functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ namespace Sass {
14741474
for (size_t i = 0, L = arglist->length(); i < L; ++i) {
14751475
Expression* expr = arglist->value_at_index(i);
14761476
if (arglist->is_arglist()) {
1477-
Argument* arg = static_cast<Argument*>(expr);
1477+
Argument* arg = static_cast<Argument*>((*arglist)[i]);
14781478
*args << new (ctx.mem) Argument(pstate,
14791479
expr,
14801480
"",

0 commit comments

Comments
 (0)