1d9b95f9e6
- `fun(f())` is now possible - Anonymous can take normal strings - Tests for `%()`
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
if (typeof(require) !== 'undefined') { var tree = require('less/tree') }
|
|
|
|
//
|
|
// A function call node.
|
|
//
|
|
tree.Call = function Call(name, args) {
|
|
this.name = name;
|
|
this.args = args;
|
|
};
|
|
tree.Call.prototype = {
|
|
//
|
|
// When evaluating a function call,
|
|
// we either find the function in `tree.functions` [1],
|
|
// in which case we call it, passing the evaluated arguments,
|
|
// or we simply print it out as it appeared originally [2].
|
|
//
|
|
// The *functions.js* file contains the built-in functions.
|
|
//
|
|
// The reason why we evaluate the arguments, is in the case where
|
|
// we try to pass a variable to a function, like: `saturate(@color)`.
|
|
// The function should receive the value, not the variable.
|
|
//
|
|
eval: function (env) {
|
|
if (this._value) return this._value;
|
|
|
|
var args = this.args.map(function (a) { return a.eval(env) });
|
|
|
|
if (this.name in tree.functions) { // 1.
|
|
return this._value = tree.functions[this.name].apply(tree.functions, args);
|
|
} else { // 2.
|
|
return this._value = new(tree.Anonymous)(this.name +
|
|
"(" + args.map(function (a) { return a.toCSS() }).join(', ') + ")");
|
|
}
|
|
},
|
|
|
|
toCSS: function (env) {
|
|
return this.eval(env).toCSS();
|
|
}
|
|
};
|