throw an error when the unit function is passed bad input. Fixes #1426

This commit is contained in:
Luke Page
2013-09-18 05:54:38 +01:00
parent 39b36d9cfc
commit 0465398ab6
4 changed files with 14 additions and 2 deletions

View File

@@ -233,6 +233,9 @@ tree.functions = {
return new(tree.Quoted)('"' + str + '"', str);
},
unit: function (val, unit) {
if(!(val instanceof tree.Dimension)) {
throw { type: "Argument", message: "the first argument to unit must be a number" + (val instanceof tree.Operation ? ". Have you forgotten parenthesis?" : "") };
}
return new(tree.Dimension)(val.value, unit ? unit.toCSS() : "");
},
convert: function (val, unit) {

View File

@@ -1,3 +1,5 @@
var less = {};
less.strictUnits = true;
var less = {
strictUnits: true,
strictMath: true
};

View File

@@ -0,0 +1,3 @@
.a {
font-size: unit(80/16,rem);
}

View File

@@ -0,0 +1,4 @@
ArgumentError: error evaluating function `unit`: the first argument to unit must be a number. Have you forgotten parenthesis? in {path}unit-function.less on line 2, column 14:
1 .a {
2 font-size: unit(80/16,rem);
3 }