Skip to content

Commit e1085b6

Browse files
committed
Merge pull request #1529 from mgreter/bugfix/restargs-and-nested-arglist
Fix sass function bug with restargs and nested arglists
2 parents ee8f6ab + 1d46370 commit e1085b6

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

src/bind.cpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,37 @@ namespace Sass {
128128
List* ls = dynamic_cast<List*>(a->value());
129129
// skip any list completely if empty
130130
if (ls && ls->empty()) continue;
131-
// check if we have rest argument
132-
(*arglist) << SASS_MEMORY_NEW(ctx.mem, Argument,
133-
a->pstate(),
134-
a->value(),
135-
a->name(),
136-
false,
137-
false);
131+
// flatten all nested arglists
132+
if (ls && ls->is_arglist()) {
133+
for (size_t i = 0, L = ls->size(); i < L; ++i) {
134+
// already have a wrapped argument
135+
if (Argument* arg = dynamic_cast<Argument*>((*ls)[i])) {
136+
(*arglist) << SASS_MEMORY_NEW(ctx.mem, Argument, *arg);
137+
}
138+
// wrap all other value types into Argument
139+
else {
140+
(*arglist) << SASS_MEMORY_NEW(ctx.mem, Argument,
141+
(*ls)[i]->pstate(),
142+
(*ls)[i],
143+
"",
144+
false,
145+
false);
146+
}
147+
}
148+
}
149+
// already have a wrapped argument
150+
else if (Argument* arg = dynamic_cast<Argument*>(a->value())) {
151+
(*arglist) << SASS_MEMORY_NEW(ctx.mem, Argument, *arg);
152+
}
153+
// wrap all other value types into Argument
154+
else {
155+
(*arglist) << SASS_MEMORY_NEW(ctx.mem, Argument,
156+
a->pstate(),
157+
a->value(),
158+
a->name(),
159+
false,
160+
false);
161+
}
138162
// check if we have rest argument
139163
if (a->is_rest_argument()) {
140164
// preserve the list separator from rest args

0 commit comments

Comments
 (0)