4
// A function call node.
6
tree.Call = function (name, args, index, currentFileInfo) {
10
this.currentFileInfo = currentFileInfo;
12
tree.Call.prototype = {
14
accept: function (visitor) {
15
this.args = visitor.visit(this.args);
18
// When evaluating a function call,
19
// we either find the function in `tree.functions` [1],
20
// in which case we call it, passing the evaluated arguments,
21
// if this returns null or we cannot find the function, we
22
// simply print it out as it appeared originally [2].
24
// The *functions.js* file contains the built-in functions.
26
// The reason why we evaluate the arguments, is in the case where
27
// we try to pass a variable to a function, like: `saturate(@color)`.
28
// The function should receive the value, not the variable.
30
eval: function (env) {
31
var args = this.args.map(function (a) { return a.eval(env); }),
32
nameLC = this.name.toLowerCase(),
35
if (nameLC in tree.functions) { // 1.
37
func = new tree.functionCall(env, this.currentFileInfo);
38
result = func[nameLC].apply(func, args);
43
throw { type: e.type || "Runtime",
44
message: "error evaluating function `" + this.name + "`" +
45
(e.message ? ': ' + e.message : ''),
46
index: this.index, filename: this.currentFileInfo.filename };
51
return new(tree.Anonymous)(this.name +
52
"(" + args.map(function (a) { return a.toCSS(env); }).join(', ') + ")");
55
toCSS: function (env) {
56
return this.eval(env).toCSS();
60
})(require('../tree'));