diff --git a/lib/less/parser.js b/lib/less/parser.js index 63fee5f0..869ff8f5 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -170,8 +170,7 @@ less.Parser = function Parser(env) { // the lower the number, the less nodes it will create in the tree. // This could matter for debugging, or if you want to access // the individual nodes in the tree. - this.optimization = this.env.optimization || 2; - + this.optimization = ('optimization' in this.env) ? this.env.optimization : 1; // // The Parser @@ -196,20 +195,10 @@ less.Parser = function Parser(env) { // delmited by '\n}' (see rationale above), // depending on the level of optimization. if (that.optimization > 0) { - if (that.optimization > 2) { - input = input.replace(/\/\*(?:[^*]|\*+[^\/*])*\*+\//g, ''); - chunks = input.split(/^(?=\n)/mg); - } else { - for (var k = 0; k < input.length; k++) { - if ((c = input.charAt(k)) === '}' && input.charCodeAt(k - 1) === 10) { - chunks.push(buff.concat('}').join('')); - buff = []; - } else { - buff.push(c); - } - } - chunks.push(buff.join('')); - } + input = input.replace(/\/\*(?:[^*]|\*+[^\/*])*\*+\//g, function (comment) { + return that.optimization > 1 ? '' : comment.replace(/\n\n+/g, '\n'); + }); + chunks = input.split(/^(?=\n)/mg); } else { chunks = [input]; } diff --git a/test/less-test.js b/test/less-test.js index 05f00871..948fc492 100644 --- a/test/less-test.js +++ b/test/less-test.js @@ -43,7 +43,8 @@ function toCSS(path, callback) { if (e) { return callback(e) } new(less.Parser)({ - paths: [require('path').dirname(path)] + paths: [require('path').dirname(path)], + optimization: 0 }).parse(str, function (err, tree) { if (err) { callback(err);