aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/compress.js b/lib/compress.js
index dfe444ad..df797bf7 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2150,7 +2150,9 @@ merge(Compressor.prototype, {
function handle_if_return(statements, compressor) {
var self = compressor.self();
var parent = compressor.parent();
- var in_lambda = self instanceof AST_Lambda;
+ var in_lambda = last_of(function(node) {
+ return node instanceof AST_Lambda;
+ });
var in_iife = in_lambda && parent && parent.TYPE == "Call";
var multiple_if_returns = has_multiple_if_returns(statements);
for (var i = statements.length; --i >= 0;) {
@@ -2253,7 +2255,7 @@ merge(Compressor.prototype, {
}
//---
// if (foo()) return x; return y; => return foo() ? x : y;
- if ((in_bool || value) && !stat.alternative && next instanceof AST_Return) {
+ if (!stat.alternative && next instanceof AST_Return) {
CHANGED = true;
stat = stat.clone();
stat.alternative = next;
@@ -2323,14 +2325,21 @@ merge(Compressor.prototype, {
return true;
}
- function match_target(target) {
+ function last_of(predicate) {
var block = self, stat, level = 0;
do {
do {
- if (block === target) return true;
+ if (predicate(block)) return true;
block = compressor.parent(level++);
} while (block instanceof AST_If && (stat = block));
- } while (block instanceof AST_BlockStatement && is_last_statement(block.body, stat));
+ } while ((block instanceof AST_BlockStatement || block instanceof AST_Scope)
+ && is_last_statement(block.body, stat));
+ }
+
+ function match_target(target) {
+ return last_of(function(node) {
+ return node === target;
+ });
}
function can_merge_flow(ab) {