generator: add isLast helper method
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user