basic support in definition, clean up and tests

This commit is contained in:
Luke Page
2012-09-09 10:17:05 +01:00
parent 587d6c2338
commit 0ab748371c
8 changed files with 36 additions and 16 deletions

View File

@@ -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

View File

@@ -0,0 +1,6 @@
.mixin(@a : 4, @b : 3, @c: 2) {
will: fail;
}
.mixin-test {
.mixin(@a: 5; @b: 6, @c: 7);
}

View 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 }

View File

@@ -0,0 +1,6 @@
.mixin(@a : 4, @b : 3, @c: 2) {
will: fail;
}
.mixin-test {
.mixin(@a: 5, @b: 6; @c: 7);
}

View 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 }

View File

@@ -1,3 +0,0 @@
.mixin(@a : 4; @b : 4, @c: 3) {
will: fail;
}

View File

@@ -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;

View File

@@ -135,7 +135,7 @@ body {
one: @a;
}
.mixin-takes-two(@a, @b) {
.mixin-takes-two(@a; @b) {
one: @a;
two: @b;
}