aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-06-12 10:34:16 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-06-12 10:34:16 -0700
commitc24c10ea77e612937f1d3e36b5909ada62587b76 (patch)
treeea5172a6f3097752481b3fd9819235f4d01cb396
parentca891e3bc03b5d74720232cf8e8006bae7a6e07a (diff)
do not write unnecessary final if in multiple blocks
-rw-r--r--src/jsifier.js6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index be8c962e..6de7ecf4 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -390,8 +390,10 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
first = false;
});
} else {
- block.entryLabels.forEach(function(entryLabel) {
- ret += indent + multipleIdent + (first ? '' : 'else ') + 'if (__label__ == ' + getLabelId(entryLabel.ident) + ') {\n';
+ block.entryLabels.forEach(function(entryLabel, i) {
+ var last = i === block.entryLabels.length-1;
+ ret += indent + multipleIdent + (first ? '' : 'else ') + // add the final |if| only when we have assertions (we have a final else there)
+ ((!last || ASSERTIONS) ? 'if (__label__ == ' + getLabelId(entryLabel.ident) + ')' : '') + ' {\n';
ret += walkBlock(entryLabel.block, indent + ' ' + multipleIdent);
ret += indent + multipleIdent + '}\n';
first = false;