mirror of
https://github.com/less/less.js.git
synced 2026-01-22 13:48:03 -05:00
fix optimizations, and errors on multi-line comments
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user