mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
Fix default variables containing comma when semi-colon seperated mixin definition. Fixes #1211
This commit is contained in:
@@ -846,7 +846,7 @@ less.Parser = function Parser(env) {
|
||||
c = $('>');
|
||||
}
|
||||
if ($('(')) {
|
||||
args = this.mixin.args.call(this, true);
|
||||
args = this.mixin.args.call(this, true).args;
|
||||
expect(')');
|
||||
}
|
||||
|
||||
@@ -863,30 +863,73 @@ less.Parser = function Parser(env) {
|
||||
restore();
|
||||
},
|
||||
args: function (isCall) {
|
||||
var expressions = [], argsSemiColon = [], isSemiColonSeperated, argsComma = [], expressionContainsNamed, name, nameLoop, value, arg, args;
|
||||
while (arg = $(this.expression)) {
|
||||
nameLoop = null;
|
||||
arg.throwAwayComments();
|
||||
value = arg;
|
||||
|
||||
// Variable
|
||||
if (arg.value.length == 1) {
|
||||
var val = arg.value[0];
|
||||
if (val instanceof tree.Variable) {
|
||||
if ($(':')) {
|
||||
if (expressions.length > 0) {
|
||||
if (isSemiColonSeperated) {
|
||||
error("Cannot mix ; and , as delimiter types");
|
||||
}
|
||||
expressionContainsNamed = true;
|
||||
}
|
||||
value = expect(this.expression);
|
||||
nameLoop = (name = val.name);
|
||||
var expressions = [], argsSemiColon = [], isSemiColonSeperated, argsComma = [], expressionContainsNamed, name, nameLoop, value, arg,
|
||||
returner = {args:null, variadic: false};
|
||||
while (true) {
|
||||
if (isCall) {
|
||||
arg = $(this.expression);
|
||||
} else {
|
||||
$(this.comment);
|
||||
if (input.charAt(i) === '.' && $(/^\.{3}/)) {
|
||||
returner.variadic = true;
|
||||
if ($(";") && !isSemiColonSeperated) {
|
||||
isSemiColonSeperated = true;
|
||||
}
|
||||
(isSemiColonSeperated ? argsSemiColon : argsComma)
|
||||
.push({ variadic: true });
|
||||
break;
|
||||
}
|
||||
arg = $(this.entities.variable) || $(this.entities.literal)
|
||||
|| $(this.entities.keyword);
|
||||
}
|
||||
|
||||
if (!arg) {
|
||||
break;
|
||||
}
|
||||
|
||||
nameLoop = null;
|
||||
if (arg.throwAwayComments) {
|
||||
arg.throwAwayComments();
|
||||
}
|
||||
value = arg;
|
||||
var val = null;
|
||||
|
||||
if (isCall) {
|
||||
// Variable
|
||||
if (arg.value.length == 1) {
|
||||
var val = arg.value[0];
|
||||
}
|
||||
} else {
|
||||
val = arg;
|
||||
}
|
||||
|
||||
if (val && val instanceof tree.Variable) {
|
||||
if ($(':')) {
|
||||
if (expressions.length > 0) {
|
||||
if (isSemiColonSeperated) {
|
||||
error("Cannot mix ; and , as delimiter types");
|
||||
}
|
||||
expressionContainsNamed = true;
|
||||
}
|
||||
value = expect(this.expression);
|
||||
nameLoop = (name = val.name);
|
||||
} else if (!isCall && $(/^\.{3}/)) {
|
||||
returner.variadic = true;
|
||||
if ($(";") && !isSemiColonSeperated) {
|
||||
isSemiColonSeperated = true;
|
||||
}
|
||||
(isSemiColonSeperated ? argsSemiColon : argsComma)
|
||||
.push({ name: arg.name, variadic: true });
|
||||
break;
|
||||
} else if (!isCall) {
|
||||
name = nameLoop = val.name;
|
||||
value = null;
|
||||
}
|
||||
}
|
||||
|
||||
expressions.push(value);
|
||||
if (value) {
|
||||
expressions.push(value);
|
||||
}
|
||||
|
||||
argsComma.push({ name:nameLoop, value:value });
|
||||
|
||||
@@ -913,8 +956,8 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
}
|
||||
|
||||
args = isSemiColonSeperated ? argsSemiColon : argsComma;
|
||||
return args;
|
||||
returner.args = isSemiColonSeperated ? argsSemiColon : argsComma;
|
||||
return returner;
|
||||
},
|
||||
//
|
||||
// A Mixin definition, with a list of parameters
|
||||
@@ -945,33 +988,9 @@ less.Parser = function Parser(env) {
|
||||
if (match = $(/^([#.](?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+)\s*\(/)) {
|
||||
name = match[1];
|
||||
|
||||
do {
|
||||
$(this.comment);
|
||||
if (input.charAt(i) === '.' && $(/^\.{3}/)) {
|
||||
variadic = true;
|
||||
params.push({ variadic: true });
|
||||
break;
|
||||
} else if (param = $(this.entities.variable) || $(this.entities.literal)
|
||||
|| $(this.entities.keyword)) {
|
||||
// Variable
|
||||
if (param instanceof tree.Variable) {
|
||||
if ($(':')) {
|
||||
value = expect(this.expression, 'expected expression');
|
||||
params.push({ name: param.name, value: value });
|
||||
} else if ($(/^\.{3}/)) {
|
||||
params.push({ name: param.name, variadic: true });
|
||||
variadic = true;
|
||||
break;
|
||||
} else {
|
||||
params.push({ name: param.name });
|
||||
}
|
||||
} else {
|
||||
params.push({ value: param });
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while ($(',') || $(';'))
|
||||
var argInfo = this.mixin.args.call(this, false);
|
||||
params = argInfo.args;
|
||||
variadic = argInfo.variadic;
|
||||
|
||||
// .mixincall("@{a}");
|
||||
// looks a bit like a mixin definition.. so we have to be nice and restore
|
||||
|
||||
@@ -102,3 +102,12 @@ body {
|
||||
defaults: 1px 1px 1px;
|
||||
defaults: 2px 2px 2px;
|
||||
}
|
||||
.selector {
|
||||
margin: 2, 2, 2, 2;
|
||||
}
|
||||
.selector2 {
|
||||
margin: 2, 2, 2, 2;
|
||||
}
|
||||
.selector3 {
|
||||
margin: 4;
|
||||
}
|
||||
|
||||
@@ -183,4 +183,23 @@ body {
|
||||
.test-mixin-default-arg {
|
||||
.mixin-default-arg();
|
||||
.mixin-default-arg(2px);
|
||||
}
|
||||
|
||||
.mixin-comma-default1(@color; @padding; @margin: 2, 2, 2, 2) {
|
||||
margin: @margin;
|
||||
}
|
||||
.selector {
|
||||
.mixin-comma-default1(#33acfe; 4);
|
||||
}
|
||||
.mixin-comma-default2(@margin: 2, 2, 2, 2;) {
|
||||
margin: @margin;
|
||||
}
|
||||
.selector2 {
|
||||
.mixin-comma-default2();
|
||||
}
|
||||
.mixin-comma-default3(@margin: 2, 2, 2, 2) {
|
||||
margin: @margin;
|
||||
}
|
||||
.selector3 {
|
||||
.mixin-comma-default3(4,2,2,2);
|
||||
}
|
||||
Reference in New Issue
Block a user