mirror of
https://github.com/less/less.js.git
synced 2026-01-23 06:07:56 -05:00
37 lines
962 B
JavaScript
37 lines
962 B
JavaScript
(function (tree) {
|
|
|
|
tree.JavaScript = function (string, index) {
|
|
this.expression = string;
|
|
this.index = index;
|
|
};
|
|
tree.JavaScript.prototype = {
|
|
toCSS: function () {
|
|
return JSON.stringify(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)] = {
|
|
value: env.frames[0].variables()[k].value,
|
|
toJS: function () {
|
|
return this.value.eval(env).toCSS();
|
|
}
|
|
};
|
|
}
|
|
|
|
try {
|
|
this.evaluated = expression.call(context);
|
|
} catch (e) {
|
|
throw { message: "JavaScript evaluation error: '" + e.name + ': ' + e.message + "'" ,
|
|
index: this.index };
|
|
}
|
|
return this;
|
|
}
|
|
};
|
|
|
|
})(require('less/tree'));
|
|
|