diff --git a/lib/less/tree/rule.js b/lib/less/tree/rule.js index a2d14f2b..ac90049c 100644 --- a/lib/less/tree/rule.js +++ b/lib/less/tree/rule.js @@ -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 { diff --git a/test/css/detached-rulesets.css b/test/css/detached-rulesets.css index b98bf60b..d723a0c4 100644 --- a/test/css/detached-rulesets.css +++ b/test/css/detached-rulesets.css @@ -42,3 +42,6 @@ html.lt-ie9 header { visible-one: visible; visible-two: visible; } +.without-mixins { + b: 1; +} diff --git a/test/less/detached-rulesets.less b/test/less/detached-rulesets.less index 57c2cb43..787cc19b 100644 --- a/test/less/detached-rulesets.less +++ b/test/less/detached-rulesets.less @@ -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(); +} diff --git a/test/less/errors/detached-ruleset-1.less b/test/less/errors/detached-ruleset-1.less new file mode 100644 index 00000000..ac5b8db0 --- /dev/null +++ b/test/less/errors/detached-ruleset-1.less @@ -0,0 +1,6 @@ +@a: { + b: 1; +}; +.a { + a: @a; +} \ No newline at end of file diff --git a/test/less/errors/detached-ruleset-1.txt b/test/less/errors/detached-ruleset-1.txt new file mode 100644 index 00000000..7407741c --- /dev/null +++ b/test/less/errors/detached-ruleset-1.txt @@ -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 } diff --git a/test/less/errors/detached-ruleset-2.less b/test/less/errors/detached-ruleset-2.less new file mode 100644 index 00000000..51a7af6b --- /dev/null +++ b/test/less/errors/detached-ruleset-2.less @@ -0,0 +1,6 @@ +@a: { + b: 1; +}; +.a { + a: @a(); +} \ No newline at end of file diff --git a/test/less/errors/detached-ruleset-2.txt b/test/less/errors/detached-ruleset-2.txt new file mode 100644 index 00000000..f18e0935 --- /dev/null +++ b/test/less/errors/detached-ruleset-2.txt @@ -0,0 +1,4 @@ +ParseError: Unrecognised input in {path}detached-ruleset-2.less on line 5, column 3: +4 .a { +5 a: @a(); +6 } diff --git a/test/less/errors/detached-ruleset-3.less b/test/less/errors/detached-ruleset-3.less new file mode 100644 index 00000000..c50119d9 --- /dev/null +++ b/test/less/errors/detached-ruleset-3.less @@ -0,0 +1,4 @@ +@a: { + b: 1; +}; +@a(); \ No newline at end of file diff --git a/test/less/errors/detached-ruleset-3.txt b/test/less/errors/detached-ruleset-3.txt new file mode 100644 index 00000000..15d281fa --- /dev/null +++ b/test/less/errors/detached-ruleset-3.txt @@ -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 }; diff --git a/test/less/errors/detached-ruleset-4.less b/test/less/errors/detached-ruleset-4.less new file mode 100644 index 00000000..14ac314b --- /dev/null +++ b/test/less/errors/detached-ruleset-4.less @@ -0,0 +1,5 @@ +.mixin-definition(@a: { + b: 1; +}) { + @a(); +} \ No newline at end of file diff --git a/test/less/errors/detached-ruleset-4.txt b/test/less/errors/detached-ruleset-4.txt new file mode 100644 index 00000000..d6d6526d --- /dev/null +++ b/test/less/errors/detached-ruleset-4.txt @@ -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; diff --git a/test/less/errors/detached-ruleset-5.less b/test/less/errors/detached-ruleset-5.less new file mode 100644 index 00000000..174ebf35 --- /dev/null +++ b/test/less/errors/detached-ruleset-5.less @@ -0,0 +1,4 @@ +.mixin-definition(@b) { + @a(); +} +.mixin-definition({color: red;}); \ No newline at end of file diff --git a/test/less/errors/detached-ruleset-5.txt b/test/less/errors/detached-ruleset-5.txt new file mode 100644 index 00000000..56189795 --- /dev/null +++ b/test/less/errors/detached-ruleset-5.txt @@ -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;}); diff --git a/test/less/errors/detached-ruleset-6.less b/test/less/errors/detached-ruleset-6.less new file mode 100644 index 00000000..121099f7 --- /dev/null +++ b/test/less/errors/detached-ruleset-6.less @@ -0,0 +1,5 @@ +.a { + b: { + color: red; + }; +} \ No newline at end of file diff --git a/test/less/errors/detached-ruleset-6.txt b/test/less/errors/detached-ruleset-6.txt new file mode 100644 index 00000000..07840445 --- /dev/null +++ b/test/less/errors/detached-ruleset-6.txt @@ -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;