error tests and test detached rulesets without a mixin call

This commit is contained in:
Luke Page
2014-02-13 21:42:32 +00:00
parent e0692fa199
commit b46ca11286
15 changed files with 76 additions and 3 deletions

View File

@@ -30,7 +30,7 @@ tree.Rule.prototype = {
},
toCSS: tree.toCSS,
eval: function (env) {
var strictMathBypass = false, name = this.name;
var strictMathBypass = false, name = this.name, evaldValue;
if (typeof name !== "string") {
// expand 'primitive' name directly to get
// things faster (~10% for benchmark.less):
@@ -43,14 +43,25 @@ tree.Rule.prototype = {
env.strictMath = true;
}
try {
evaldValue = this.value.eval(env);
if (!this.variable && evaldValue.type === "Ruleset") {
console.log(this.index);
throw { message: "Rulesets cannot be evaluated on a property.",
index: this.index, filename: this.currentFileInfo.filename };
}
return new(tree.Rule)(name,
this.value.eval(env),
evaldValue,
this.important,
this.merge,
this.index, this.currentFileInfo, this.inline);
}
catch(e) {
e.index = e.index || this.index;
if (typeof e.index !== 'number') {
e.index = this.index;
e.filename = this.currentFileInfo.filename;
}
throw e;
}
finally {

View File

@@ -42,3 +42,6 @@ html.lt-ie9 header {
visible-one: visible;
visible-two: visible;
}
.without-mixins {
b: 1;
}

View File

@@ -56,3 +56,10 @@ header {
test-func: unit(90px);
test-arithmetic: unit((9+9), px);
});
// without mixins
@ruleset-2: {
b: 1;
};
.without-mixins {
@ruleset-2();
}

View File

@@ -0,0 +1,6 @@
@a: {
b: 1;
};
.a {
a: @a;
}

View File

@@ -0,0 +1,4 @@
SyntaxError: Rulesets cannot be evaluated on a property. in {path}detached-ruleset-1.less on line 5, column 3:
4 .a {
5 a: @a;
6 }

View File

@@ -0,0 +1,6 @@
@a: {
b: 1;
};
.a {
a: @a();
}

View File

@@ -0,0 +1,4 @@
ParseError: Unrecognised input in {path}detached-ruleset-2.less on line 5, column 3:
4 .a {
5 a: @a();
6 }

View File

@@ -0,0 +1,4 @@
@a: {
b: 1;
};
@a();

View File

@@ -0,0 +1,4 @@
SyntaxError: properties must be inside selector blocks, they cannot be in the root. in {path}detached-ruleset-3.less on line 2, column 3:
1 @a: {
2 b: 1;
3 };

View File

@@ -0,0 +1,5 @@
.mixin-definition(@a: {
b: 1;
}) {
@a();
}

View File

@@ -0,0 +1,3 @@
ParseError: Unrecognised input in {path}detached-ruleset-4.less on line 1, column 18:
1 .mixin-definition(@a: {
2 b: 1;

View File

@@ -0,0 +1,4 @@
.mixin-definition(@b) {
@a();
}
.mixin-definition({color: red;});

View File

@@ -0,0 +1,3 @@
SyntaxError: variable @a is undefined in {path}detached-ruleset-5.less on line 4, column 1:
3 }
4 .mixin-definition({color: red;});

View File

@@ -0,0 +1,5 @@
.a {
b: {
color: red;
};
}

View File

@@ -0,0 +1,4 @@
ParseError: Unrecognised input in {path}detached-ruleset-6.less on line 2, column 3:
1 .a {
2 b: {
3 color: red;