From 01ae902eff20b85715f6f4e7616531c4c5f81efc Mon Sep 17 00:00:00 2001 From: cloudhead Date: Tue, 23 Feb 2010 23:20:38 -0500 Subject: [PATCH] chunkify with a zero-width regexp --- lib/less/parser.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/less/parser.js b/lib/less/parser.js index 08acffac..df3ed0cd 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -120,15 +120,15 @@ less.parser = { // parse: function (str) { var tree; - input = str; - - inputLength = input.length; - chunks = input.split(/\n\n/g); - for (var k = 0; k < chunks.length; k++) { - if (k < chunks.length - 1) { chunks[k] += '\n' } - if (k) { chunks[k] = '\n' + chunks[k] } - } + input = str; + 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); // Start with the primary rule tree = new(node.Ruleset)([], $(this.parsers.primary, []));