From bf2a49a12e79ac168b59c23174e96c3e8e511722 Mon Sep 17 00:00:00 2001 From: deviprsd21 Date: Sat, 11 Jan 2014 17:43:24 +0530 Subject: [PATCH] Improved min/max function, 2 new Built in function max(0, 1em, 2, 4px) //returns 4px on the basis of first enter basis. Previous calculation would result in max(2, 1em, 4px). Here, 2 and 1em is compared, 2 is returned. then 2 and 4px is compared. Resulting in 4px. max(0, 1em, 1, 4px) //max(1em, 4px) --- lib/less/functions.js | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/lib/less/functions.js b/lib/less/functions.js index cbddee5e..85145b7e 100644 --- a/lib/less/functions.js +++ b/lib/less/functions.js @@ -276,29 +276,12 @@ tree.functions = { 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]; + unit = currentUnified.unit.toString() === "" && unitStatic !== undefined ? unitStatic : currentUnified.unit.toString(); + unitStatic = unit !== "" && unitStatic === undefined || unit !== "" && order[0].unify().unit.toString() === "" ? unit : unitStatic; + values[unit] = values[""] !== undefined && unit !== "" && unit === unitStatic ? values[""] : 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; }