don't append a newline to the last switchcase

This commit is contained in:
Sebastian McKenzie
2015-02-21 12:27:38 +11:00
parent 6220fd9fc3
commit b03a806d7c
2 changed files with 10 additions and 1 deletions

View File

@@ -148,7 +148,14 @@ exports.SwitchStatement = function (node, print) {
this.push(")");
this.space();
this.push("{");
print.sequence(node.cases, { indent: true });
print.sequence(node.cases, {
indent: true,
addNewlines: function (leading, cas) {
if (!leading && node.cases[node.cases.length - 1] === cas) return -1;
}
});
this.push("}");
};

View File

@@ -174,6 +174,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
} else {
// generated node
if (!leading) lines++; // always include at least a single line after
if (opts.addNewlines) lines += opts.addNewlines(leading, node) || 0;
var needs = n.needsWhitespaceAfter;
if (leading) needs = n.needsWhitespaceBefore;
@@ -234,6 +235,7 @@ CodeGenerator.prototype.printJoin = function (print, nodes, opts) {
each(nodes, function (node, i) {
print(node, {
statement: opts.statement,
addNewlines: opts.addNewlines,
after: function () {
if (opts.iterator) {
opts.iterator(node, i);