3 tree.JavaScript = function (string, index, escaped) {
4 this.escaped = escaped;
5 this.expression = string;
8 tree.JavaScript.prototype = {
14 var expression = this.expression.replace(/@\{([\w-]+)\}/g, function (_, name) {
15 return tree.jsify(new(tree.Variable)('@' + name, that.index).eval(env));
19 expression = new(Function)('return (' + expression + ')');
21 throw { message: "JavaScript evaluation error: `" + expression + "`" ,
25 for (var k in env.frames[0].variables()) {
26 context[k.slice(1)] = {
27 value: env.frames[0].variables()[k].value,
29 return this.value.eval(env).toCSS();
35 result = expression.call(context);
37 throw { message: "JavaScript evaluation error: '" + e.name + ': ' + e.message + "'" ,
40 if (typeof(result) === 'string') {
41 return new(tree.Quoted)('"' + result + '"', result, this.escaped, this.index);
42 } else if (Array.isArray(result)) {
43 return new(tree.Anonymous)(result.join(', '));
45 return new(tree.Anonymous)(result);
50 })(require('less/tree'));