From f197b2a0f8a95e4df93c1c15a2438a8380d01cb8 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Thu, 10 Nov 2011 21:24:25 -0800 Subject: [PATCH] store index on selector element objects for line number inference --- lib/less/parser.js | 6 +++--- lib/less/tree/element.js | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/less/parser.js b/lib/less/parser.js index 1e04645d..9657eb4e 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -680,7 +680,7 @@ less.Parser = function Parser(env) { if (s !== '.' && s !== '#') { return } while (e = $(/^[#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/)) { - elements.push(new(tree.Element)(c, e)); + elements.push(new(tree.Element)(c, e, i)); c = $('>'); } $('(') && (args = $(this.entities.arguments)) && $(')'); @@ -799,10 +799,10 @@ less.Parser = function Parser(env) { c = $(this.combinator); e = $(/^(?:[.#]?|:*)(?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/) || $('*') || $(this.attribute) || $(/^\([^)@]+\)/) || $(/^(?:\d*\.)?\d+%/); - if (e) { return new(tree.Element)(c, e) } + if (e) { return new(tree.Element)(c, e, i) } if (c.value && c.value[0] === '&') { - return new(tree.Element)(c, null); + return new(tree.Element)(c, null, i); } }, diff --git a/lib/less/tree/element.js b/lib/less/tree/element.js index 27cf8228..a2f19bea 100644 --- a/lib/less/tree/element.js +++ b/lib/less/tree/element.js @@ -1,9 +1,10 @@ (function (tree) { -tree.Element = function (combinator, value) { +tree.Element = function (combinator, value, index) { this.combinator = combinator instanceof tree.Combinator ? combinator : new(tree.Combinator)(combinator); this.value = value ? value.trim() : ""; + this.index = index; }; tree.Element.prototype.toCSS = function (env) { return this.combinator.toCSS(env || {}) + this.value;