From fca3a0c56f29e2d91d152d2183e37977f1fde716 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 4 Nov 2014 08:04:32 +1100 Subject: [PATCH] generator: add ensureSemicolon and printBlock methods --- lib/6to5/generator.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/6to5/generator.js b/lib/6to5/generator.js index 200c5c6b3c..d22edeec38 100644 --- a/lib/6to5/generator.js +++ b/lib/6to5/generator.js @@ -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