Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 65c43fb

Browse files
committed
Improve arglist handling
Fixes #1259 Fixes #1305
1 parent 6706f09 commit 65c43fb

File tree

3 files changed

+36
-46
lines changed

3 files changed

+36
-46
lines changed

ast.cpp

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -911,21 +911,38 @@ namespace Sass {
911911
}
912912
}
913913

914-
/* not used anymore - remove?
915-
vector<Compound_Selector*> Complex_Selector::to_vector()
914+
void Arguments::adjust_after_pushing(Argument* a)
916915
{
917-
vector<Compound_Selector*> result;
918-
Compound_Selector* h = head();
919-
Complex_Selector* t = tail();
920-
if (h) result.push_back(h);
921-
while (t)
922-
{
923-
h = t->head();
924-
t = t->tail();
925-
if (h) result.push_back(h);
916+
if (!a->name().empty()) {
917+
if (/* has_rest_argument_ || */ has_keyword_argument_) {
918+
error("named arguments must precede variable-length argument", a->pstate());
919+
}
920+
has_named_arguments_ = true;
926921
}
927-
return result;
928-
}*/
922+
else if (a->is_rest_argument()) {
923+
if (has_rest_argument_) {
924+
error("functions and mixins may only be called with one variable-length argument", a->pstate());
925+
}
926+
if (has_keyword_argument_) {
927+
error("only keyword arguments may follow variable arguments", a->pstate());
928+
}
929+
has_rest_argument_ = true;
930+
}
931+
else if (a->is_keyword_argument()) {
932+
if (has_keyword_argument_) {
933+
error("functions and mixins may only be called with one keyword argument", a->pstate());
934+
}
935+
has_keyword_argument_ = true;
936+
}
937+
else {
938+
if (has_rest_argument_) {
939+
error("ordinal arguments must precede variable-length arguments", a->pstate());
940+
}
941+
if (has_named_arguments_) {
942+
error("ordinal arguments must precede named arguments", a->pstate());
943+
}
944+
}
945+
}
929946

930947
Number::Number(ParserState pstate, double val, string u, bool zero)
931948
: Expression(pstate),

ast.hpp

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,38 +1015,7 @@ namespace Sass {
10151015
ADD_PROPERTY(bool, has_rest_argument)
10161016
ADD_PROPERTY(bool, has_keyword_argument)
10171017
protected:
1018-
void adjust_after_pushing(Argument* a)
1019-
{
1020-
if (!a->name().empty()) {
1021-
if (has_rest_argument_ || has_keyword_argument_) {
1022-
error("named arguments must precede variable-length argument", a->pstate());
1023-
}
1024-
has_named_arguments_ = true;
1025-
}
1026-
else if (a->is_rest_argument()) {
1027-
if (has_rest_argument_) {
1028-
error("functions and mixins may only be called with one variable-length argument", a->pstate());
1029-
}
1030-
if (has_keyword_argument_) {
1031-
error("only keyword arguments may follow variable arguments", a->pstate());
1032-
}
1033-
has_rest_argument_ = true;
1034-
}
1035-
else if (a->is_keyword_argument()) {
1036-
if (has_keyword_argument_) {
1037-
error("functions and mixins may only be called with one keyword argument", a->pstate());
1038-
}
1039-
has_keyword_argument_ = true;
1040-
}
1041-
else {
1042-
if (has_rest_argument_) {
1043-
error("ordinal arguments must precede variable-length arguments", a->pstate());
1044-
}
1045-
if (has_named_arguments_) {
1046-
error("ordinal arguments must precede named arguments", a->pstate());
1047-
}
1048-
}
1049-
}
1018+
void adjust_after_pushing(Argument* a);
10501019
public:
10511020
Arguments(ParserState pstate)
10521021
: Expression(pstate),

bind.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ namespace Sass {
121121
while (ia < LA) {
122122
// get and post inc
123123
a = (*as)[ia++];
124-
// wrap current argument into new object
124+
// maybe we have another list as argument
125+
List* ls = dynamic_cast<List*>(a->value());
126+
// skip any list completely if empty
127+
if (ls && ls->empty()) continue;
128+
// check if we have rest argument
125129
(*arglist) << new (ctx.mem) Argument(a->pstate(),
126130
a->value(),
127131
a->name(),

0 commit comments

Comments
 (0)