From fcf6c9e066ffa1a7d97142c094019ade855dadb5 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sat, 1 Nov 2014 17:53:01 +1100 Subject: [PATCH] generator: add isLast helper method --- lib/6to5/generator.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/6to5/generator.js b/lib/6to5/generator.js index c3ba631a88..6f48131261 100644 --- a/lib/6to5/generator.js +++ b/lib/6to5/generator.js @@ -70,7 +70,7 @@ CodeGenerator.prototype.push = function (str) { str = str.replace(/\n/g, "\n" + indent); // we've got a newline before us so prepend on the indentation - if (_.last(this.buf) === "\n") str = indent + str; + if (this.isLast("\n")) str = indent + str; } var self = this; @@ -87,6 +87,10 @@ CodeGenerator.prototype.push = function (str) { this.buf += str; }; +CodeGenerator.prototype.isLast = function (cha) { + return _.last(this.buf) === cha; +}; + CodeGenerator.prototype.getIndent = function () { return util.repeat(this._indent * this.tabWidth); };