[Pkg-javascript-commits] [less.js] 05/88: Improved min/max function, 2 new Built in function

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:22:21 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 08e613709e93eed8d36b08574f3df9cd1bdb3ebd
Author: deviprsd21 <deviprsd21 at gmail.com>
Date:   Fri Jan 10 22:48:37 2014 +0530

    Improved min/max function, 2 new Built in function
---
 lib/less/functions.js | 34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/lib/less/functions.js b/lib/less/functions.js
index 3f58ec2..cbddee5 100644
--- a/lib/less/functions.js
+++ b/lib/less/functions.js
@@ -264,24 +264,41 @@ tree.functions = {
     _minmax: function (isMin, args) {
         args = Array.prototype.slice.call(args);
         switch(args.length) {
-        case 0: throw { type: "Argument", message: "one or more arguments required" };
-        case 1: return args[0];
+            case 0: throw { type: "Argument", message: "one or more arguments required" };
         }
-        var i, j, current, currentUnified, referenceUnified, unit,
+        var i, j, current, currentUnified, referenceUnified, unit, unitStatic,
             order  = [], // elems only contains original argument values.
             values = {}; // key is the unit.toString() for unified tree.Dimension values,
                          // value is the index into the order array.
         for (i = 0; i < args.length; i++) {
             current = args[i];
             if (!(current instanceof tree.Dimension)) {
-                order.push(current);
                 continue;
             }
             currentUnified = current.unify();
             unit = currentUnified.unit.toString();
+            if(unit === "" && unitStatic !== undefined) {
+                unit = unitStatic;
+            } else if(unit === "") {
+                unit = "variable";
+            }
+            unitStatic = unit !== "variable" && unitStatic === undefined ? unit : unitStatic;
+            values[unit] = values["variable"] !== undefined && unit !== "variable" && unit === unitStatic ? values["variable"] : values[unit];
             j = values[unit];
             if (j === undefined) {
                 values[unit] = order.length;
+                //error handling for incompatible types
+                if((values["px"] !== undefined && values["em"] !== undefined) || (values["px"] !== undefined && values["%"] !== undefined) ||
+                   (values["px"] !== undefined && values["m"] !== undefined) || (values["px"] !== undefined && values["s"] !== undefined) ||
+                   (values["px"] !== undefined && values["rad"] !== undefined) || (values["em"] !== undefined && values["%"] !== undefined) ||
+                   (values["em"] !== undefined && values["m"] !== undefined) || (values["em"] !== undefined && values["s"] !== undefined) ||
+                   (values["em"] !== undefined && values["rad"] !== undefined) || (values["%"] !== undefined && values["m"] !== undefined) ||
+                   (values["%"] !== undefined && values["s"] !== undefined) || (values["%"] !== undefined && values["rad"] !== undefined) ||
+                   (values["m"] !== undefined && values["s"] !== undefined) || (values["m"] !== undefined && values["rad"] !== undefined) ||
+                   (values["s"] !== undefined && values["rad"] !== undefined))
+                {
+                    throw { type: "Argument", message: "incompatible types" };
+                }
                 order.push(current);
                 continue;
             }
@@ -294,8 +311,7 @@ tree.functions = {
         if (order.length == 1) {
             return order[0];
         }
-        args = order.map(function (a) { return a.toCSS(this.env); })
-                    .join(this.env.compress ? "," : ", ");
+        args = order.map(function (a) { return a.toCSS(this.env); }).join(this.env.compress ? "," : ", ");
         return new(tree.Anonymous)((isMin ? "min" : "max") + "(" + args + ")");
     },
     min: function () {
@@ -304,6 +320,12 @@ tree.functions = {
     max: function () {
         return this._minmax(false, arguments);
     },
+	zero: function (n) {
+        return new(tree.Dimension)(n.value, n.value ? n.unit : '');
+    },
+    unitonly: function (n) {
+        return new(tree.Anonymous)(n.unit);
+    },
     argb: function (color) {
         return new(tree.Anonymous)(color.toARGB());
     },

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