improved the chunkification process, and gave different options, as well as an option not to chunkify, through the optimization
setting. The ideal split is now \n}
This commit is contained in:
parent
aec37061e1
commit
fd8aa91ddc
@ -41,7 +41,7 @@ var less = exports || {};
|
||||
var input, // LeSS input string
|
||||
i, // current index in `input`
|
||||
j, // current chunk
|
||||
chunks = [], // chunkified input
|
||||
chunks, // chunkified input
|
||||
current, // index of current chunk, in `input`
|
||||
inputLength;
|
||||
|
||||
@ -117,21 +117,40 @@ function $(tok, root) {
|
||||
}
|
||||
|
||||
less.parser = {
|
||||
optimization: 2,
|
||||
//
|
||||
// Parse an input string into an abstract syntax tree
|
||||
//
|
||||
parse: function (str) {
|
||||
var tree, start, end, zone, line;
|
||||
var tree, start, end, zone, line, buff = [], c;
|
||||
|
||||
i = j = current = 0;
|
||||
chunks = [];
|
||||
input = str.replace(/\r\n/g, '\n');
|
||||
inputLength = input.length;
|
||||
|
||||
// Split the input into chunks,
|
||||
// delmited by /\n\n/ (see rationale above)
|
||||
// We use a lookahead, because we want to
|
||||
// preserve the '\n's in the input.
|
||||
chunks = input.split(/^(?=\n)/mg);
|
||||
// Either delimited by /\n\n/ or
|
||||
// delmited by '\n}' (see rationale above),
|
||||
// depending on the level of optimization.
|
||||
if (this.optimization > 0) {
|
||||
if (this.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(''));
|
||||
}
|
||||
} else {
|
||||
chunks = [input];
|
||||
}
|
||||
|
||||
// Start with the primary rule
|
||||
tree = new(node.Ruleset)([], $(this.parsers.primary, []));
|
||||
|
Loading…
Reference in New Issue
Block a user