Merge pull request #450 from fat/index-on-element-root

store index on selector element objects for line number inference
This commit is contained in:
Alexis Sellier
2011-11-11 03:47:44 -08:00
2 changed files with 5 additions and 4 deletions

View File

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

View File

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