diff --git a/lib/less/tree/mixin.js b/lib/less/tree/mixin.js index 2908d981..fbb6780e 100644 --- a/lib/less/tree/mixin.js +++ b/lib/less/tree/mixin.js @@ -109,7 +109,6 @@ tree.mixin.Definition.prototype = { this.rules = visitor.visit(this.rules); this.condition = visitor.visit(this.condition); }, - toCSS: function () { return ""; }, variable: function (name) { return this.parent.variable.call(this, name); }, variables: function () { return this.parent.variables.call(this); }, find: function () { return this.parent.find.apply(this, arguments); }, diff --git a/lib/less/tree/negative.js b/lib/less/tree/negative.js index 3342d82e..e36b6084 100644 --- a/lib/less/tree/negative.js +++ b/lib/less/tree/negative.js @@ -9,11 +9,10 @@ tree.Negative.prototype = { this.value = visitor.visit(this.value); }, genCSS: function (env, output) { - output.add(this.toCSS(env)); - }, - toCSS: function (env) { - return '-' + this.value.toCSS(env); + output.add('-'); + this.value.genCSS(env, output) }, + toCSS: tree.toCSS, eval: function (env) { if (env.isMathOn()) { return (new(tree.Operation)('*', [new(tree.Dimension)(-1), this.value])).eval(env); diff --git a/lib/less/tree/operation.js b/lib/less/tree/operation.js index 807d8f88..8909f14f 100644 --- a/lib/less/tree/operation.js +++ b/lib/less/tree/operation.js @@ -35,12 +35,17 @@ tree.Operation.prototype = { } }, genCSS: function (env, output) { - output.add(this.toCSS(env)); + this.operands[0].genCSS(env, output); + if (this.isSpaced) { + output.add(" "); + } + output.add(this.op); + if (this.isSpaced) { + output.add(" "); + } + this.operands[1].genCSS(env, output) }, - toCSS: function (env) { - var separator = this.isSpaced ? " " : ""; - return this.operands[0].toCSS() + separator + this.op + separator + this.operands[1].toCSS(); - } + toCSS: tree.toCSS }; tree.operate = function (env, op, a, b) { diff --git a/lib/less/tree/paren.js b/lib/less/tree/paren.js index 3bd65d41..e27b8d66 100644 --- a/lib/less/tree/paren.js +++ b/lib/less/tree/paren.js @@ -10,11 +10,11 @@ tree.Paren.prototype = { this.value = visitor.visit(this.value); }, genCSS: function (env, output) { - output.add(this.toCSS(env)); - }, - toCSS: function (env) { - return '(' + this.value.toCSS(env).trim() + ')'; + output.add('('); + this.value.genCSS(env, output); + output.add(')'); }, + toCSS: tree.toCSS, eval: function (env) { return new(tree.Paren)(this.value.eval(env)); } diff --git a/lib/less/tree/quoted.js b/lib/less/tree/quoted.js index 188cc2bb..e78accad 100644 --- a/lib/less/tree/quoted.js +++ b/lib/less/tree/quoted.js @@ -10,15 +10,15 @@ tree.Quoted = function (str, content, escaped, index, currentFileInfo) { tree.Quoted.prototype = { type: "Quoted", genCSS: function (env, output) { - output.add(this.toCSS(env)); - }, - toCSS: function () { - if (this.escaped) { - return this.value; - } else { - return this.quote + this.value + this.quote; + if (!this.escaped) { + output.add(this.quote); + } + output.add(this.value); + if (!this.escaped) { + output.add(this.quote); } }, + toCSS: tree.toCSS, eval: function (env) { var that = this; var value = this.value.replace(/`([^`]+)`/g, function (_, exp) { diff --git a/lib/less/tree/rule.js b/lib/less/tree/rule.js index cafe6d08..e8fe085d 100644 --- a/lib/less/tree/rule.js +++ b/lib/less/tree/rule.js @@ -17,24 +17,18 @@ tree.Rule.prototype = { this.value = visitor.visit(this.value); }, genCSS: function (env, output) { - output.add(this.toCSS(env)); - }, - toCSS: function (env) { - if (this.variable) { return ""; } - else { - try { - var css = this.name + (env.compress ? ':' : ': ') + - this.value.toCSS(env) + - this.important + ((this.inline || (env.lastRule && env.compress)) ? "" : ";"); - return css; - } - catch(e) { - e.index = this.index; - e.filename = this.currentFileInfo.filename; - throw e; - } + output.add(this.name + (env.compress ? ':' : ': ')); + try { + this.value.genCSS(env, output); } + catch(e) { + e.index = this.index; + e.filename = this.currentFileInfo.filename; + throw e; + } + output.add(this.important + ((this.inline || (env.lastRule && env.compress)) ? "" : ";")); }, + toCSS: tree.toCSS, eval: function (env) { var strictMathBypass = false; if (this.name === "font" && env.strictMath === false) { diff --git a/lib/less/tree/selector.js b/lib/less/tree/selector.js index 2a2f1cdc..1e10be14 100644 --- a/lib/less/tree/selector.js +++ b/lib/less/tree/selector.js @@ -55,29 +55,19 @@ tree.Selector.prototype = { }), evaldCondition); }, genCSS: function (env, output) { - output.add(this.toCSS(env)); - }, - toCSS: function (env) { - - if (!this._css) { - //surprised this caching works since the first element combinator is changed from ' ' to '' - //in the toCSS visitor, when toCSS may have already been called? - //is this caching worth it? - this._css = this.elements.map(function (e) { - if (typeof(e) === 'string') { - return ' ' + e.trim(); - } else { - return e.toCSS(env); - } - }).join(''); - } - + var i, element; if ((!env || !env.firstSelector) && this.elements[0].combinator.value === "") { - return ' ' + this._css; + output.add(' '); + } + if (!this._css) { + //TODO caching? speed comparison? + for(i = 0; i < this.elements.length; i++) { + element = this.elements[i]; + element.genCSS(env, output); + } } - - return this._css; }, + toCSS: tree.toCSS, markReferenced: function () { this.isReferenced = true; }, diff --git a/lib/less/tree/unicode-descriptor.js b/lib/less/tree/unicode-descriptor.js index aa465686..7bf98ea5 100644 --- a/lib/less/tree/unicode-descriptor.js +++ b/lib/less/tree/unicode-descriptor.js @@ -6,11 +6,9 @@ tree.UnicodeDescriptor = function (value) { tree.UnicodeDescriptor.prototype = { type: "UnicodeDescriptor", genCSS: function (env, output) { - output.add(this.toCSS(env)); - }, - toCSS: function (env) { - return this.value; + output.add(this.value); }, + toCSS: tree.toCSS, eval: function () { return this; } }; diff --git a/lib/less/tree/url.js b/lib/less/tree/url.js index c8b72059..b2b91e8b 100644 --- a/lib/less/tree/url.js +++ b/lib/less/tree/url.js @@ -10,11 +10,11 @@ tree.URL.prototype = { this.value = visitor.visit(this.value); }, genCSS: function (env, output) { - output.add(this.toCSS(env)); - }, - toCSS: function () { - return "url(" + this.value.toCSS() + ")"; + output.add("url("); + this.value.genCSS(env, output) + output.add(")"); }, + toCSS: tree.toCSS, eval: function (ctx) { var val = this.value.eval(ctx), rootpath; diff --git a/lib/less/tree/value.js b/lib/less/tree/value.js index 2deebb57..7f110f65 100644 --- a/lib/less/tree/value.js +++ b/lib/less/tree/value.js @@ -18,13 +18,15 @@ tree.Value.prototype = { } }, genCSS: function (env, output) { - output.add(this.toCSS(env)); + var i; + for(i = 0; i < this.value.length; i++) { + this.value[i].genCSS(env, output); + if (i+1 < this.value.length) { + output.add(env.compress ? ',' : ', '); + } + } }, - toCSS: function (env) { - return this.value.map(function (e) { - return e.toCSS(env); - }).join(env.compress ? ',' : ', '); - } + toCSS: tree.toCSS }; })(require('../tree'));