aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-02-26 03:14:22 +0800
committerGitHub <noreply@github.com>2018-02-26 03:14:22 +0800
commitb8b2ac5230f4ea94ddc6fdb407825b6d2ff7da8d (patch)
treea1aa2c3c1b851bf35e063d45c278e5c842f812b8 /lib
parentea2359381b737a60b7879d60b756a575271252b7 (diff)
downloadtracifyjs-b8b2ac5230f4ea94ddc6fdb407825b6d2ff7da8d.tar.gz
tracifyjs-b8b2ac5230f4ea94ddc6fdb407825b6d2ff7da8d.zip
improve fix for #2954 (#2958)
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js31
1 files changed, 20 insertions, 11 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 2d0a03ae..c402e3ba 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -913,8 +913,8 @@ merge(Compressor.prototype, {
}
function tighten_body(statements, compressor) {
- var scope = compressor.find_parent(AST_Scope);
- var in_loop = is_in_node(AST_IterationStatement);
+ var in_loop, in_try, scope;
+ find_loop_scope_try();
var CHANGED, max_iter = 10;
do {
CHANGED = false;
@@ -937,13 +937,20 @@ merge(Compressor.prototype, {
}
} while (CHANGED && max_iter-- > 0);
- function is_in_node(type) {
- if (compressor.self() instanceof type) return true;
- for (var node, level = 0; node = compressor.parent(level); level++) {
- if (node instanceof type) return true;
- if (node instanceof AST_Scope) break;
- }
- return false;
+ function find_loop_scope_try() {
+ var node = compressor.self(), level = 0;
+ do {
+ if (node instanceof AST_Catch || node instanceof AST_Finally) {
+ level++;
+ } else if (node instanceof AST_IterationStatement) {
+ in_loop = true;
+ } else if (node instanceof AST_Scope) {
+ scope = node;
+ break;
+ } else if (node instanceof AST_Try) {
+ in_try = true;
+ }
+ } while (node = compressor.parent(level++));
}
// Search from right to left for assignment-like expressions:
@@ -958,7 +965,6 @@ merge(Compressor.prototype, {
if (scope.uses_eval || scope.uses_with) return statements;
var args;
var candidates = [];
- var in_try = is_in_node(AST_Try);
var stat_index = statements.length;
var scanner = new TreeTransformer(function(node, descend) {
if (abort) return node;
@@ -1433,7 +1439,10 @@ merge(Compressor.prototype, {
if (def.orig.length == 1 && def.orig[0] instanceof AST_SymbolDefun) return false;
if (def.scope !== scope) return true;
return !all(def.references, function(ref) {
- return ref.scope === scope;
+ var s = ref.scope;
+ // "block" scope within AST_Catch
+ if (s.TYPE == "Scope") s = s.parent_scope;
+ return s === scope;
});
}