Revert "Export"
[platform/framework/web/web-ui-fw.git] / build-tools / lib / less / tree / call.js
1 (function (tree) {
2
3 //
4 // A function call node.
5 //
6 tree.Call = function (name, args, index) {
7     this.name = name;
8     this.args = args;
9     this.index = index;
10 };
11 tree.Call.prototype = {
12     //
13     // When evaluating a function call,
14     // we either find the function in `tree.functions` [1],
15     // in which case we call it, passing the  evaluated arguments,
16     // or we simply print it out as it appeared originally [2].
17     //
18     // The *functions.js* file contains the built-in functions.
19     //
20     // The reason why we evaluate the arguments, is in the case where
21     // we try to pass a variable to a function, like: `saturate(@color)`.
22     // The function should receive the value, not the variable.
23     //
24     eval: function (env) {
25         var args = this.args.map(function (a) { return a.eval(env) });
26
27         if (this.name in tree.functions) { // 1.
28             try {
29                 return tree.functions[this.name].apply(tree.functions, args);
30             } catch (e) {
31                 throw { message: "error evaluating function `" + this.name + "`",
32                         index: this.index };
33             }
34         } else { // 2.
35             return new(tree.Anonymous)(this.name +
36                    "(" + args.map(function (a) { return a.toCSS() }).join(', ') + ")");
37         }
38     },
39
40     toCSS: function (env) {
41         return this.eval(env).toCSS();
42     }
43 };
44
45 })(require('less/tree'));