[Pkg-javascript-commits] [less.js] 48/88: error tests and test detached rulesets without a mixin call

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:22:25 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag v1.7.0
in repository less.js.

commit b46ca11286e3c4fb8eb351ff01725cc9c4223add
Author: Luke Page <luke.a.page at gmail.com>
Date:   Thu Feb 13 21:42:32 2014 +0000

    error tests and test detached rulesets without a mixin call
---
 lib/less/tree/rule.js                    | 17 ++++++++++++++---
 test/css/detached-rulesets.css           |  3 +++
 test/less/detached-rulesets.less         |  7 +++++++
 test/less/errors/detached-ruleset-1.less |  6 ++++++
 test/less/errors/detached-ruleset-1.txt  |  4 ++++
 test/less/errors/detached-ruleset-2.less |  6 ++++++
 test/less/errors/detached-ruleset-2.txt  |  4 ++++
 test/less/errors/detached-ruleset-3.less |  4 ++++
 test/less/errors/detached-ruleset-3.txt  |  4 ++++
 test/less/errors/detached-ruleset-4.less |  5 +++++
 test/less/errors/detached-ruleset-4.txt  |  3 +++
 test/less/errors/detached-ruleset-5.less |  4 ++++
 test/less/errors/detached-ruleset-5.txt  |  3 +++
 test/less/errors/detached-ruleset-6.less |  5 +++++
 test/less/errors/detached-ruleset-6.txt  |  4 ++++
 15 files changed, 76 insertions(+), 3 deletions(-)

diff --git a/lib/less/tree/rule.js b/lib/less/tree/rule.js
index a2d14f2..ac90049 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 b98bf60..d723a0c 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 57c2cb4..787cc19 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
+ at 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 0000000..ac5b8db
--- /dev/null
+++ b/test/less/errors/detached-ruleset-1.less
@@ -0,0 +1,6 @@
+ at 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 0000000..7407741
--- /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 0000000..51a7af6
--- /dev/null
+++ b/test/less/errors/detached-ruleset-2.less
@@ -0,0 +1,6 @@
+ at 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 0000000..f18e093
--- /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 0000000..c50119d
--- /dev/null
+++ b/test/less/errors/detached-ruleset-3.less
@@ -0,0 +1,4 @@
+ at a: {
+  b: 1;
+};
+ at 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 0000000..15d281f
--- /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 0000000..14ac314
--- /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 0000000..d6d6526
--- /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 0000000..174ebf3
--- /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 0000000..5618979
--- /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 0000000..121099f
--- /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 0000000..0784044
--- /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;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git



More information about the Pkg-javascript-commits mailing list