diff --git a/lib/6to5/generator.js b/lib/6to5/generator.js index 1b3f60cd14..6f83d625c7 100644 --- a/lib/6to5/generator.js +++ b/lib/6to5/generator.js @@ -56,6 +56,7 @@ CodeGenerator.prototype.mark = function (node, type) { CodeGenerator.prototype.newline = function (i, removeLast) { if (!this.buf) return; + if (this.endsWith("{\n")) return; if (_.isBoolean(i)) { removeLast = i; @@ -159,6 +160,10 @@ CodeGenerator.prototype._push = function (str) { this.buf += str; }; +CodeGenerator.prototype.endsWith = function (str) { + return this.buf.slice(-str.length) === str; +}; + CodeGenerator.prototype.isLast = function (cha, trimRight) { var buf = this.buf; if (trimRight) buf = buf.trimRight(); @@ -189,7 +194,6 @@ CodeGenerator.prototype.generate = function () { this.print(ast); this.buf = this.buf.trimRight(); - this.buf = this.buf.replace(/\{\n\n/g, "{\n"); var map = this.map; if (map) map = map.toJSON();