mirror of
https://github.com/less/less.js.git
synced 2026-01-23 06:07:56 -05:00
33 lines
858 B
JavaScript
33 lines
858 B
JavaScript
(function (tree) {
|
|
|
|
tree.JavaScript = function (string, index) {
|
|
this.expression = string;
|
|
this.index = index;
|
|
};
|
|
tree.JavaScript.prototype = {
|
|
toCSS: function () {
|
|
return this.evaluated;
|
|
},
|
|
eval: function (env) {
|
|
var result,
|
|
expression = new(Function)('return (' + this.expression + ')'),
|
|
context = {};
|
|
|
|
for (var k in env.frames[0].variables()) {
|
|
context[k.slice(1)] = env.frames[0].variables()[k].value.eval(env).toCSS();
|
|
}
|
|
|
|
try {
|
|
result = expression.call(context);
|
|
this.evaluated = JSON.stringify(result);
|
|
} catch (e) {
|
|
throw { message: "JavaScript evaluation error: '" + e.name + ': ' + e.message + "'" ,
|
|
index: this.index };
|
|
}
|
|
return this;
|
|
}
|
|
};
|
|
|
|
})(require('less/tree'));
|
|
|