From 0fbf0e2a770c63d5ceed94fa476e59c78b2bb0ee Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 31 Oct 2014 21:24:54 +1100 Subject: [PATCH] generator: add semicolon helper method, add optional printJoin iterator --- lib/6to5/generator.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/6to5/generator.js b/lib/6to5/generator.js index 762643b7a8..c03c29cba8 100644 --- a/lib/6to5/generator.js +++ b/lib/6to5/generator.js @@ -57,6 +57,10 @@ CodeGenerator.prototype.newline = function () { this.buf += "\n"; }; +CodeGenerator.prototype.semicolon = function () { + this.buf += ";"; +}; + CodeGenerator.prototype.push = function (str) { if (this._indent) { // we have an indent level and we aren't pushing a newline @@ -164,33 +168,28 @@ CodeGenerator.prototype.printLeadingComments = function (node) { }); }; -CodeGenerator.prototype.printJoin = function (print, nodes, sep, indent) { - sep = sep || "\n"; +CodeGenerator.prototype.printJoin = function (print, nodes, sep, opts) { + opts = opts || {}; + sep = sep || "\n"; var self = this; var len = nodes.length; - if (indent) self.indent(); + if (opts.indent) self.indent(); _.each(nodes, function (node, i) { - print(node); + if (opts.iterator) { + opts.iterator(node, i); + } else { + print(node); + } if (i < len - 1) { self.push(sep); } }); - if (indent) self.dedent(); -}; - -CodeGenerator.prototype.removeEmptyExpressions = function (nodes) { - return nodes.filter(function (node) { - if (node.type === "EmptyStatement") { - return false; - } else { - return true; - } - }); + if (opts.indent) self.dedent(); }; CodeGenerator.generators = {