mirror of
https://github.com/less/less.js.git
synced 2026-01-22 21:58:14 -05:00
basic support in definition, clean up and tests
This commit is contained in:
@@ -802,7 +802,7 @@ less.Parser = function Parser(env) {
|
||||
// selector for now.
|
||||
//
|
||||
call: function () {
|
||||
var elements = [], e, c, argsSemiColon = [], argsComma = [], args, delim, arg, nameLoop, expressions, isSemiColonSeperated, index = i, s = input.charAt(i), name, value, important = false;
|
||||
var elements = [], e, c, argsSemiColon = [], argsComma = [], args, delim, arg, nameLoop, expressions, isSemiColonSeperated, expressionContainsNamed, index = i, s = input.charAt(i), name, value, important = false;
|
||||
|
||||
if (s !== '.' && s !== '#') { return }
|
||||
|
||||
@@ -813,9 +813,6 @@ less.Parser = function Parser(env) {
|
||||
c = $('>');
|
||||
}
|
||||
if ($('(')) {
|
||||
//todo remove
|
||||
name = null;
|
||||
isSemiColonSeperated = false;
|
||||
expressions = [];
|
||||
while (arg = $(this.expression)) {
|
||||
nameLoop = null;
|
||||
@@ -826,8 +823,11 @@ less.Parser = function Parser(env) {
|
||||
var val = arg.value[0];
|
||||
if (val instanceof tree.Variable) {
|
||||
if ($(':')) {
|
||||
if (isSemiColonSeperated && expressions.length > 1) {
|
||||
error("Cannot mix ; and , as delimiter types");
|
||||
if (expressions.length > 0) {
|
||||
if (isSemiColonSeperated) {
|
||||
error("Cannot mix ; and , as delimiter types");
|
||||
}
|
||||
expressionContainsNamed = true;
|
||||
}
|
||||
value = expect(this.expression);
|
||||
nameLoop = (name = val.name);
|
||||
@@ -844,6 +844,11 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
|
||||
if ($(';') || isSemiColonSeperated) {
|
||||
|
||||
if (expressionContainsNamed) {
|
||||
error("Cannot mix ; and , as delimiter types");
|
||||
}
|
||||
|
||||
isSemiColonSeperated = true;
|
||||
|
||||
if (expressions.length > 1) {
|
||||
@@ -853,10 +858,11 @@ less.Parser = function Parser(env) {
|
||||
|
||||
name = null;
|
||||
expressions = [];
|
||||
expressionContainsNamed = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $(')')) throw new(Error)("Expected )");
|
||||
expect(')');
|
||||
}
|
||||
|
||||
args = isSemiColonSeperated ? argsSemiColon : argsComma;
|
||||
@@ -894,7 +900,7 @@ less.Parser = function Parser(env) {
|
||||
definition: function () {
|
||||
var name, params = [], match, ruleset, param, value, cond, variadic = false;
|
||||
if ((input.charAt(i) !== '.' && input.charAt(i) !== '#') ||
|
||||
peek(/^[^{]*(;|})/)) return;
|
||||
peek(/^[^{]*\}/)) return;
|
||||
|
||||
save();
|
||||
|
||||
@@ -926,7 +932,7 @@ less.Parser = function Parser(env) {
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while ($(','))
|
||||
} while ($(',') || $(';'))
|
||||
|
||||
// .mixincall("@{a}");
|
||||
// looks a bit like a mixin definition.. so we have to be nice and restore
|
||||
|
||||
6
test/less/errors/mixed-mixin-definition-args-1.less
Normal file
6
test/less/errors/mixed-mixin-definition-args-1.less
Normal file
@@ -0,0 +1,6 @@
|
||||
.mixin(@a : 4, @b : 3, @c: 2) {
|
||||
will: fail;
|
||||
}
|
||||
.mixin-test {
|
||||
.mixin(@a: 5; @b: 6, @c: 7);
|
||||
}
|
||||
4
test/less/errors/mixed-mixin-definition-args-1.txt
Normal file
4
test/less/errors/mixed-mixin-definition-args-1.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
SyntaxError: Cannot mix ; and , as delimiter types in {path}mixed-mixin-definition-args-1.less:5:29
|
||||
4 .mixin-test {
|
||||
5 .mixin(@a: 5; @b: 6, @c: 7);
|
||||
6 }
|
||||
6
test/less/errors/mixed-mixin-definition-args-2.less
Normal file
6
test/less/errors/mixed-mixin-definition-args-2.less
Normal file
@@ -0,0 +1,6 @@
|
||||
.mixin(@a : 4, @b : 3, @c: 2) {
|
||||
will: fail;
|
||||
}
|
||||
.mixin-test {
|
||||
.mixin(@a: 5, @b: 6; @c: 7);
|
||||
}
|
||||
4
test/less/errors/mixed-mixin-definition-args-2.txt
Normal file
4
test/less/errors/mixed-mixin-definition-args-2.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
SyntaxError: Cannot mix ; and , as delimiter types in {path}mixed-mixin-definition-args-2.less:5:25
|
||||
4 .mixin-test {
|
||||
5 .mixin(@a: 5, @b: 6; @c: 7);
|
||||
6 }
|
||||
@@ -1,3 +0,0 @@
|
||||
.mixin(@a : 4; @b : 4, @c: 3) {
|
||||
will: fail;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
ParseError: Syntax Error on line 1 in {path}mixed-mixin-definition-args.less:1:10
|
||||
1 .mixin(@a : 4; @b : 4, @c: 3) {
|
||||
2 will: fail;
|
||||
@@ -135,7 +135,7 @@ body {
|
||||
one: @a;
|
||||
}
|
||||
|
||||
.mixin-takes-two(@a, @b) {
|
||||
.mixin-takes-two(@a; @b) {
|
||||
one: @a;
|
||||
two: @b;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user