4
// A function call node.
6
tree.Call = function (name, args, index, filename) {
10
this.filename = filename;
12
tree.Call.prototype = {
14
// When evaluating a function call,
15
// we either find the function in `tree.functions` [1],
16
// in which case we call it, passing the evaluated arguments,
17
// or we simply print it out as it appeared originally [2].
19
// The *functions.js* file contains the built-in functions.
21
// The reason why we evaluate the arguments, is in the case where
22
// we try to pass a variable to a function, like: `saturate(@color)`.
23
// The function should receive the value, not the variable.
25
eval: function (env) {
26
var args = this.args.map(function (a) { return a.eval(env) });
28
if (this.name in tree.functions) { // 1.
30
return tree.functions[this.name].apply(tree.functions, args);
32
throw { type: e.type || "Runtime",
33
message: "error evaluating function `" + this.name + "`" +
34
(e.message ? ': ' + e.message : ''),
35
index: this.index, filename: this.filename };
38
return new(tree.Anonymous)(this.name +
39
"(" + args.map(function (a) { return a.toCSS() }).join(', ') + ")");
43
toCSS: function (env) {
44
return this.eval(env).toCSS();
48
})(require('../tree'));