generator: add ensureSemicolon and printBlock methods

This commit is contained in:
Sebastian McKenzie 2014-11-04 08:04:32 +11:00
parent e88505aba6
commit fca3a0c56f

View File

@ -70,11 +70,24 @@ CodeGenerator.prototype.semicolon = function () {
this._push(";");
};
CodeGenerator.prototype.ensureSemicolon = function () {
if (!this.isLast(";")) this.semicolon();
};
CodeGenerator.prototype.keyword = function (name) {
this.push(name);
this.push(" ");
};
CodeGenerator.prototype.printBlock = function (print, node) {
if (t.isEmptyStatement(node)) {
this.semicolon();
} else {
this.push(" ");
print(node);
}
};
CodeGenerator.prototype.push = function (str, noIndent) {
if (this._indent && !noIndent && str !== "\n") {
// we have an indent level and we aren't pushing a newline