fix excessive whitespace trimming resulting in innaccurate sourcemap line - fixes #151

This commit is contained in:
Sebastian McKenzie
2014-11-13 12:25:11 +11:00
parent 0c7e0b65b9
commit 9c1b60e451
29 changed files with 12 additions and 39 deletions

View File

@@ -76,6 +76,8 @@ Buffer.prototype.newline = function (i, removeLast) {
}
if (_.isNumber(i)) {
if (this.endsWith(util.repeat(i, "\n"))) return;
var self = this;
_.times(i, function () {
self.newline(null, removeLast);
@@ -86,7 +88,7 @@ Buffer.prototype.newline = function (i, removeLast) {
if (removeLast && this.isLast("\n")) this.removeLast("\n");
this.removeLast(" ");
this.buf = this.buf.replace(/\n(\s+)$/, "\n");
this.buf = this.buf.replace(/\n +$/, "\n");
this._push("\n");
};

View File

@@ -115,8 +115,6 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
opts = opts || {};
var newline = function (leading) {
var ignoreDuplicates = false;
if (!opts.statement && !n.isUserWhitespacable(node, parent)) {
return;
}
@@ -139,7 +137,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
lines += needs(node, parent);
}
self.newline(lines, ignoreDuplicates);
self.newline(lines);
};
if (this[node.type]) {