generator: add semicolon helper method, add optional printJoin iterator
This commit is contained in:
parent
e8628ea1a7
commit
0fbf0e2a77
@ -57,6 +57,10 @@ CodeGenerator.prototype.newline = function () {
|
|||||||
this.buf += "\n";
|
this.buf += "\n";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CodeGenerator.prototype.semicolon = function () {
|
||||||
|
this.buf += ";";
|
||||||
|
};
|
||||||
|
|
||||||
CodeGenerator.prototype.push = function (str) {
|
CodeGenerator.prototype.push = function (str) {
|
||||||
if (this._indent) {
|
if (this._indent) {
|
||||||
// we have an indent level and we aren't pushing a newline
|
// 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) {
|
CodeGenerator.prototype.printJoin = function (print, nodes, sep, opts) {
|
||||||
|
opts = opts || {};
|
||||||
sep = sep || "\n";
|
sep = sep || "\n";
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var len = nodes.length;
|
var len = nodes.length;
|
||||||
|
|
||||||
if (indent) self.indent();
|
if (opts.indent) self.indent();
|
||||||
|
|
||||||
_.each(nodes, function (node, i) {
|
_.each(nodes, function (node, i) {
|
||||||
|
if (opts.iterator) {
|
||||||
|
opts.iterator(node, i);
|
||||||
|
} else {
|
||||||
print(node);
|
print(node);
|
||||||
|
}
|
||||||
|
|
||||||
if (i < len - 1) {
|
if (i < len - 1) {
|
||||||
self.push(sep);
|
self.push(sep);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (indent) self.dedent();
|
if (opts.indent) self.dedent();
|
||||||
};
|
|
||||||
|
|
||||||
CodeGenerator.prototype.removeEmptyExpressions = function (nodes) {
|
|
||||||
return nodes.filter(function (node) {
|
|
||||||
if (node.type === "EmptyStatement") {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CodeGenerator.generators = {
|
CodeGenerator.generators = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user