From b043fd4507db4a8cbdd67f9ccd5a0b7dba19ea21 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Tue, 24 May 2011 17:05:17 -0400 Subject: [PATCH] catch errors on css function calls --- lib/less/parser.js | 4 ++-- lib/less/tree/call.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/less/parser.js b/lib/less/parser.js index 6d0da7b5..d83bb458 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -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; diff --git a/lib/less/tree/call.js b/lib/less/tree/call.js index c2353e54..4a72932b 100644 --- a/lib/less/tree/call.js +++ b/lib/less/tree/call.js @@ -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(', ') + ")");