aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-02-18 04:36:00 +0800
committerGitHub <noreply@github.com>2018-02-18 04:36:00 +0800
commit2351a672ea4fae04353f0221cec7ffb6c2c3bdc0 (patch)
tree5687af3ccdd3331eb93ac3e54cc92339e34cc407 /lib/compress.js
parent4a528c469c8b962912c8628fb312e772dd77fe2f (diff)
downloadtracifyjs-2351a672ea4fae04353f0221cec7ffb6c2c3bdc0.tar.gz
tracifyjs-2351a672ea4fae04353f0221cec7ffb6c2c3bdc0.zip
fix `dead_code` on exceptional `return` (#2930)
fixes #2929
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/compress.js b/lib/compress.js
index f8e9f916..2cc8282a 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2863,6 +2863,9 @@ merge(Compressor.prototype, {
def(AST_ObjectProperty, function(compressor){
return this.value.may_throw(compressor);
});
+ def(AST_Return, function(compressor){
+ return this.value.may_throw(compressor);
+ });
def(AST_Sequence, function(compressor){
return any(this.expressions, compressor);
});
@@ -2882,8 +2885,7 @@ merge(Compressor.prototype, {
return !this.is_declared(compressor);
});
def(AST_Try, function(compressor){
- return any(this.body, compressor)
- || this.bcatch && this.bcatch.may_throw(compressor)
+ return this.bcatch ? this.bcatch.may_throw(compressor) : any(this.body, compressor)
|| this.bfinally && this.bfinally.may_throw(compressor);
});
def(AST_Unary, function(compressor){
@@ -5511,7 +5513,7 @@ merge(Compressor.prototype, {
node = parent;
parent = compressor.parent(level++);
if (parent instanceof AST_Exit) {
- if (in_try(level, parent instanceof AST_Throw)) break;
+ if (in_try(level, parent)) break;
if (is_reachable(def.scope, [ def ])) break;
if (self.operator == "=") return self.right;
def.fixed = false;
@@ -5545,13 +5547,17 @@ merge(Compressor.prototype, {
}
return self;
- function in_try(level, no_catch) {
+ function in_try(level, node) {
+ var right = self.right;
+ self.right = make_node(AST_Null, right);
+ var may_throw = node.may_throw(compressor);
+ self.right = right;
var scope = self.left.definition().scope;
var parent;
while ((parent = compressor.parent(level++)) !== scope) {
if (parent instanceof AST_Try) {
if (parent.bfinally) return true;
- if (no_catch && parent.bcatch) return true;
+ if (may_throw && parent.bcatch) return true;
}
}
}