mirror of
https://github.com/less/less.js.git
synced 2026-05-01 03:00:22 -04:00
Evaluate function calls properly.
- `fun(f())` is now possible - Anonymous can take normal strings - Tests for `%()`
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
if (typeof(require) !== 'undefined') { var tree = require('less/tree') }
|
||||
|
||||
tree.Anonymous = function Anonymous(string) {
|
||||
this.value = string.content;
|
||||
this.value = string.content || string;
|
||||
};
|
||||
tree.Anonymous.prototype = {
|
||||
toCSS: function () {
|
||||
|
||||
@@ -8,10 +8,8 @@ tree.Call = function Call(name, args) {
|
||||
this.args = args;
|
||||
};
|
||||
tree.Call.prototype = {
|
||||
eval: function (env) { return this },
|
||||
|
||||
//
|
||||
// When generating CSS from a function call,
|
||||
// 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].
|
||||
@@ -22,14 +20,20 @@ tree.Call.prototype = {
|
||||
// we try to pass a variable to a function, like: `saturate(@color)`.
|
||||
// The function should receive the value, not the variable.
|
||||
//
|
||||
toCSS: function (context, env) {
|
||||
var args = this.args.map(function (a) { return a.eval(context) });
|
||||
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 tree.functions[this.name].apply(tree.functions, args).toCSS();
|
||||
return this._value = tree.functions[this.name].apply(tree.functions, args);
|
||||
} else { // 2.
|
||||
return this.name +
|
||||
"(" + args.map(function (a) { return a.toCSS() }).join(', ') + ")";
|
||||
return this._value = new(tree.Anonymous)(this.name +
|
||||
"(" + args.map(function (a) { return a.toCSS() }).join(', ') + ")");
|
||||
}
|
||||
},
|
||||
|
||||
toCSS: function (env) {
|
||||
return this.eval(env).toCSS();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user