fix optimizations, and errors on multi-line comments

This commit is contained in:
cloudhead
2010-06-01 21:21:59 -04:00
parent 799697b8c3
commit 9c390cbdf8
2 changed files with 7 additions and 17 deletions

View File

@@ -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];
}

View File

@@ -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);