aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-10-24 09:33:32 +0300
committerMihai Bazon <mihai@bazon.net>2012-10-24 09:33:32 +0300
commit70fd2b1f336535188696d9e7b198b8acd31aa558 (patch)
tree4279039cd90f45e8840198449efcc715cc8a9f90
parent30faaf13edca3a4db6867e8faf0f0b68c6ac11e0 (diff)
downloadtracifyjs-70fd2b1f336535188696d9e7b198b8acd31aa558.tar.gz
tracifyjs-70fd2b1f336535188696d9e7b198b8acd31aa558.zip
fix for `if (...) return; else return ...;`
(it was assumed that the first `return` always contains a value) close #22
-rw-r--r--lib/compress.js4
-rw-r--r--test/compress/issue-22.js17
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 22fb330e..2ea91d0c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1220,8 +1220,8 @@ merge(Compressor.prototype, {
return make_node(self.body.CTOR, self, {
value: make_node(AST_Conditional, self, {
condition : self.condition,
- consequent : self.body.value,
- alternative : self.alternative.value || make_node(AST_Undefined, self).optimize(compressor)
+ consequent : self.body.value || make_node(AST_Undefined, self.body).optimize(compressor),
+ alternative : self.alternative.value || make_node(AST_Undefined, self.alternative).optimize(compressor)
})
}).transform(compressor);
}
diff --git a/test/compress/issue-22.js b/test/compress/issue-22.js
new file mode 100644
index 00000000..a8b7bc60
--- /dev/null
+++ b/test/compress/issue-22.js
@@ -0,0 +1,17 @@
+return_with_no_value_in_if_body: {
+ options = { conditionals: true };
+ input: {
+ function foo(bar) {
+ if (bar) {
+ return;
+ } else {
+ return 1;
+ }
+ }
+ }
+ expect: {
+ function foo (bar) {
+ return bar ? void 0 : 1;
+ }
+ }
+}