small fixes to sourcemaps

This commit is contained in:
Luke Page
2013-07-19 19:26:24 +01:00
parent 8c3e304966
commit 63109417c7
9 changed files with 21 additions and 12 deletions

View File

@@ -335,7 +335,8 @@
firstElement = new tree.Element(
match.initialCombinator,
replacementSelector.elements[0].value,
replacementSelector.elements[0].index
replacementSelector.elements[0].index,
replacementSelector.elements[0].currentFileInfo
);
if (match.pathIndex > currentSelectorPathIndex && currentSelectorPathElementIndex > 0) {

View File

@@ -928,7 +928,7 @@ less.Parser = function Parser(env) {
save(); // stop us absorbing part of an invalid selector
while (e = $(/^[#.](?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/)) {
elements.push(new(tree.Element)(c, e, i));
elements.push(new(tree.Element)(c, e, i, env.currentFileInfo));
c = $('>');
}
if ($('(')) {
@@ -1167,7 +1167,7 @@ less.Parser = function Parser(env) {
}
}
if (e) { return new(tree.Element)(c, e, i); }
if (e) { return new(tree.Element)(c, e, i, env.currentFileInfo); }
},
//

View File

@@ -26,7 +26,7 @@
var inputSource = this._contentsMap[fileInfo.filename].substring(0, index);
lines = inputSource.split("\n");
columns = lines[lines.length-1];
this._sourceMapGenerator.addMapping({ generated: { line: this._lineNumber, column: this._column}, original: { line: lines.length - 1, column: columns.length}, source: fileInfo.filename});
this._sourceMapGenerator.addMapping({ generated: { line: this._lineNumber + 1, column: this._column}, original: { line: lines.length, column: columns.length}, source: fileInfo.filename});
}
lines = chunk.split("\n");
columns = lines[lines.length-1];

View File

@@ -1,6 +1,6 @@
(function (tree) {
tree.Element = function (combinator, value, index) {
tree.Element = function (combinator, value, index, currentFileInfo) {
this.combinator = combinator instanceof tree.Combinator ?
combinator : new(tree.Combinator)(combinator);
@@ -12,6 +12,7 @@ tree.Element = function (combinator, value, index) {
this.value = "";
}
this.index = index;
this.currentFileInfo = currentFileInfo;
};
tree.Element.prototype = {
type: "Element",
@@ -22,10 +23,11 @@ tree.Element.prototype = {
eval: function (env) {
return new(tree.Element)(this.combinator,
this.value.eval ? this.value.eval(env) : this.value,
this.index);
this.index,
this.currentFileInfo);
},
genCSS: function (env, output) {
output.add(this.toCSS(env));
output.add(this.toCSS(env), this.currentFileInfo, this.index);
},
toCSS: function (env) {
var value = (this.value.toCSS ? this.value.toCSS(env) : this.value);

View File

@@ -63,7 +63,7 @@ tree.Media.prototype = {
find: function () { return tree.Ruleset.prototype.find.apply(this.rules[0], arguments); },
rulesets: function () { return tree.Ruleset.prototype.rulesets.apply(this.rules[0]); },
emptySelectors: function() {
var el = new(tree.Element)('', '&', 0);
var el = new(tree.Element)('', '&', this.index, this.currentFileInfo);
return [new(tree.Selector)([el], null, null, this.index, this.currentFileInfo)];
},
markReferenced: function () {

View File

@@ -88,7 +88,7 @@ tree.mixin.Call.prototype = {
tree.mixin.Definition = function (name, params, rules, condition, variadic) {
this.name = name;
this.selectors = [new(tree.Selector)([new(tree.Element)(null, name)])];
this.selectors = [new(tree.Selector)([new(tree.Element)(null, name, this.index, this.currentFileInfo)])];
this.params = params;
this.condition = condition;
this.variadic = variadic;

View File

@@ -359,7 +359,7 @@ tree.Ruleset.prototype = {
// it is not lost
if (sel.length > 0) {
sel[0].elements = sel[0].elements.slice(0);
sel[0].elements.push(new(tree.Element)(el.combinator, '', 0)); //new Element(el.Combinator, ""));
sel[0].elements.push(new(tree.Element)(el.combinator, '', 0, el.index, el.currentFileInfo));
}
selectorsMultiplied.push(sel);
}
@@ -397,7 +397,7 @@ tree.Ruleset.prototype = {
newJoinedSelectorEmpty = false;
// join the elements so far with the first part of the parent
newJoinedSelector.elements.push(new(tree.Element)(el.combinator, parentSel[0].elements[0].value, 0));
newJoinedSelector.elements.push(new(tree.Element)(el.combinator, parentSel[0].elements[0].value, el.index, el.currentFileInfo));
newJoinedSelector.elements = newJoinedSelector.elements.concat(parentSel[0].elements.slice(1));
}

View File

@@ -57,7 +57,7 @@ tree.Selector.prototype = {
genCSS: function (env, output) {
var i, element;
if ((!env || !env.firstSelector) && this.elements[0].combinator.value === "") {
output.add(' ');
output.add(' ', this.currentFileInfo, this.index);
}
if (!this._css) {
//TODO caching? speed comparison?

View File

@@ -62,6 +62,12 @@ function testSourcemap(name, err, compiledLess, doReplacements, sourcemap) {
sys.print("- " + name + ": ");
if (sourcemap === expectedSourcemap) {
ok('OK');
} else if (err) {
fail("ERROR: " + (err && err.message));
if (isVerbose) {
console.error();
console.error(err.stack);
}
} else {
difference("FAIL", expectedSourcemap, sourcemap);
}