generator: add isLast helper method

This commit is contained in:
Sebastian McKenzie
2014-11-01 17:53:01 +11:00
parent a5523664fc
commit fcf6c9e066

View File

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