Skip to content

Commit d302fe8

Browse files
committed
refactor mixin call arguments into a seperate function
1 parent 7217cb5 commit d302fe8

File tree

1 file changed

+56
-52
lines changed

1 file changed

+56
-52
lines changed

lib/less/parser.js

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ less.Parser = function Parser(env) {
835835
// selector for now.
836836
//
837837
call: function () {
838-
var elements = [], e, c, argsSemiColon = [], argsComma = [], args, delim, arg, nameLoop, expressions, isSemiColonSeperated, expressionContainsNamed, index = i, s = input.charAt(i), name, value, important = false;
838+
var elements = [], e, c, args, delim, arg, index = i, s = input.charAt(i), important = false;
839839

840840
if (s !== '.' && s !== '#') { return }
841841

@@ -846,60 +846,11 @@ less.Parser = function Parser(env) {
846846
c = $('>');
847847
}
848848
if ($('(')) {
849-
expressions = [];
850-
while (arg = $(this.expression)) {
851-
nameLoop = null;
852-
arg.throwAwayComments();
853-
value = arg;
854-
855-
// Variable
856-
if (arg.value.length == 1) {
857-
var val = arg.value[0];
858-
if (val instanceof tree.Variable) {
859-
if ($(':')) {
860-
if (expressions.length > 0) {
861-
if (isSemiColonSeperated) {
862-
error("Cannot mix ; and , as delimiter types");
863-
}
864-
expressionContainsNamed = true;
865-
}
866-
value = expect(this.expression);
867-
nameLoop = (name = val.name);
868-
}
869-
}
870-
}
871-
872-
expressions.push(value);
873-
874-
argsComma.push({ name: nameLoop, value: value });
875-
876-
if ($(',')) {
877-
continue;
878-
}
879-
880-
if ($(';') || isSemiColonSeperated) {
881-
882-
if (expressionContainsNamed) {
883-
error("Cannot mix ; and , as delimiter types");
884-
}
885-
886-
isSemiColonSeperated = true;
887-
888-
if (expressions.length > 1) {
889-
value = new(tree.Value)(expressions);
890-
}
891-
argsSemiColon.push({ name: name, value: value });
892-
893-
name = null;
894-
expressions = [];
895-
expressionContainsNamed = false;
896-
}
897-
}
898-
849+
args = this.mixin.args.call(this, true);
899850
expect(')');
900851
}
901852

902-
args = isSemiColonSeperated ? argsSemiColon : argsComma;
853+
args = args || [];
903854

904855
if ($(this.important)) {
905856
important = true;
@@ -911,7 +862,60 @@ less.Parser = function Parser(env) {
911862

912863
restore();
913864
},
865+
args: function (isCall) {
866+
var expressions = [], argsSemiColon = [], isSemiColonSeperated, argsComma = [], expressionContainsNamed, name, nameLoop, value, arg, args;
867+
while (arg = $(this.expression)) {
868+
nameLoop = null;
869+
arg.throwAwayComments();
870+
value = arg;
871+
872+
// Variable
873+
if (arg.value.length == 1) {
874+
var val = arg.value[0];
875+
if (val instanceof tree.Variable) {
876+
if ($(':')) {
877+
if (expressions.length > 0) {
878+
if (isSemiColonSeperated) {
879+
error("Cannot mix ; and , as delimiter types");
880+
}
881+
expressionContainsNamed = true;
882+
}
883+
value = expect(this.expression);
884+
nameLoop = (name = val.name);
885+
}
886+
}
887+
}
914888

889+
expressions.push(value);
890+
891+
argsComma.push({ name:nameLoop, value:value });
892+
893+
if ($(',')) {
894+
continue;
895+
}
896+
897+
if ($(';') || isSemiColonSeperated) {
898+
899+
if (expressionContainsNamed) {
900+
error("Cannot mix ; and , as delimiter types");
901+
}
902+
903+
isSemiColonSeperated = true;
904+
905+
if (expressions.length > 1) {
906+
value = new (tree.Value)(expressions);
907+
}
908+
argsSemiColon.push({ name:name, value:value });
909+
910+
name = null;
911+
expressions = [];
912+
expressionContainsNamed = false;
913+
}
914+
}
915+
916+
args = isSemiColonSeperated ? argsSemiColon : argsComma;
917+
return args;
918+
},
915919
//
916920
// A Mixin definition, with a list of parameters
917921
//

0 commit comments

Comments
 (0)