catch errors on css function calls

This commit is contained in:
cloudhead
2011-05-24 17:05:17 -04:00
parent 4417ef62c6
commit b043fd4507
2 changed files with 10 additions and 4 deletions

View File

@@ -490,7 +490,7 @@ less.Parser = function Parser(env) {
// The arguments are parsed with the `entities.arguments` parser.
//
call: function () {
var name, args;
var name, args, index = i;
if (! (name = /^([\w-]+|%)\(/.exec(chunks[j]))) return;
@@ -507,7 +507,7 @@ less.Parser = function Parser(env) {
if (! $(')')) return;
if (name) { return new(tree.Call)(name, args) }
if (name) { return new(tree.Call)(name, args, index) }
},
arguments: function () {
var args = [], arg;

View File

@@ -3,9 +3,10 @@
//
// A function call node.
//
tree.Call = function (name, args) {
tree.Call = function (name, args, index) {
this.name = name;
this.args = args;
this.index = index;
};
tree.Call.prototype = {
//
@@ -24,7 +25,12 @@ tree.Call.prototype = {
var args = this.args.map(function (a) { return a.eval(env) });
if (this.name in tree.functions) { // 1.
return tree.functions[this.name].apply(tree.functions, args);
try {
return tree.functions[this.name].apply(tree.functions, args);
} catch (e) {
throw { message: "error evaluating function `" + this.name + "`",
index: this.index };
}
} else { // 2.
return new(tree.Anonymous)(this.name +
"(" + args.map(function (a) { return a.toCSS() }).join(', ') + ")");