diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-03-29 04:40:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-29 04:40:05 +0800 |
commit | fef0bf9ee0367f07dfbca26b144c2995c2b5db5f (patch) | |
tree | 729fb76868b8bd6a3df16131a892c02da430adb1 /lib | |
parent | ae740b933fe9cad714f5a9aac625ae2857d5a04a (diff) | |
download | tracifyjs-fef0bf9ee0367f07dfbca26b144c2995c2b5db5f.tar.gz tracifyjs-fef0bf9ee0367f07dfbca26b144c2995c2b5db5f.zip |
improve beautified output of switch blocks (#1721)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/output.js | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/output.js b/lib/output.js index c0f10523..5c11088b 100644 --- a/lib/output.js +++ b/lib/output.js @@ -960,24 +960,24 @@ function OutputStream(options) { self.expression.print(output); }); output.space(); - if (self.body.length > 0) output.with_block(function(){ - self.body.forEach(function(stmt, i){ - if (i) output.newline(); + var last = self.body.length - 1; + if (last < 0) output.print("{}"); + else output.with_block(function(){ + self.body.forEach(function(branch, i){ output.indent(true); - stmt.print(output); + branch.print(output); + if (i < last && branch.body.length > 0) + output.newline(); }); }); - else output.print("{}"); }); AST_SwitchBranch.DEFMETHOD("_do_print_body", function(output){ - if (this.body.length > 0) { + output.newline(); + this.body.forEach(function(stmt){ + output.indent(); + stmt.print(output); output.newline(); - this.body.forEach(function(stmt){ - output.indent(); - stmt.print(output); - output.newline(); - }); - } + }); }); DEFPRINT(AST_Default, function(self, output){ output.print("default:"); |