fix for if (...) return; else return ...;
(it was assumed that the first `return` always contains a value) close #22
This commit is contained in:
@@ -1220,8 +1220,8 @@ merge(Compressor.prototype, {
|
|||||||
return make_node(self.body.CTOR, self, {
|
return make_node(self.body.CTOR, self, {
|
||||||
value: make_node(AST_Conditional, self, {
|
value: make_node(AST_Conditional, self, {
|
||||||
condition : self.condition,
|
condition : self.condition,
|
||||||
consequent : self.body.value,
|
consequent : self.body.value || make_node(AST_Undefined, self.body).optimize(compressor),
|
||||||
alternative : self.alternative.value || make_node(AST_Undefined, self).optimize(compressor)
|
alternative : self.alternative.value || make_node(AST_Undefined, self.alternative).optimize(compressor)
|
||||||
})
|
})
|
||||||
}).transform(compressor);
|
}).transform(compressor);
|
||||||
}
|
}
|
||||||
|
|||||||
17
test/compress/issue-22.js
Normal file
17
test/compress/issue-22.js
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user