aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-04-07 12:32:56 +0800
committerGitHub <noreply@github.com>2017-04-07 12:32:56 +0800
commit281e882d27ace48c5c415f19292e2590dd4473dc (patch)
treea8a1a1fdae3a6f30aec01e1fc9c0a58173391ac4 /lib/compress.js
parentcc6aa3e5ac13c0da9f2481181f5b4f11275ca8c8 (diff)
downloadtracifyjs-281e882d27ace48c5c415f19292e2590dd4473dc.tar.gz
tracifyjs-281e882d27ace48c5c415f19292e2590dd4473dc.zip
fix `reduce_vars` on catch variable (#1794)
Improved catch handling in `figure_out_scope()` means special case treatment of IE8 is no longer valid in `reset_opt_flags()`. Also fixed recursive assignment in variable definition.
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js38
1 files changed, 17 insertions, 21 deletions
diff --git a/lib/compress.js b/lib/compress.js
index de3b4db2..8df6e58f 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -251,9 +251,7 @@ merge(Compressor.prototype, {
AST_Node.DEFMETHOD("reset_opt_flags", function(compressor, rescan){
var reduce_vars = rescan && compressor.option("reduce_vars");
var toplevel = compressor.option("toplevel");
- var ie8 = !compressor.option("screw_ie8");
- var safe_ids = [];
- push();
+ var safe_ids = Object.create(null);
var suppressor = new TreeWalker(function(node) {
if (node instanceof AST_Symbol) {
var d = node.definition();
@@ -277,7 +275,7 @@ merge(Compressor.prototype, {
d.fixed = false;
}
}
- if (ie8 && node instanceof AST_SymbolCatch) {
+ if (node instanceof AST_SymbolCatch) {
node.definition().fixed = false;
}
if (node instanceof AST_VarDef) {
@@ -287,11 +285,12 @@ merge(Compressor.prototype, {
d.fixed = function() {
return node.value;
};
+ mark(d, false);
descend();
} else {
d.fixed = null;
}
- mark_as_safe(d);
+ mark(d, true);
return true;
} else if (node.value) {
d.fixed = false;
@@ -303,11 +302,10 @@ merge(Compressor.prototype, {
d.fixed = false;
} else {
d.fixed = node;
- mark_as_safe(d);
+ mark(d, true);
}
var save_ids = safe_ids;
- safe_ids = [];
- push();
+ safe_ids = Object.create(null);
descend();
safe_ids = save_ids;
return true;
@@ -325,7 +323,7 @@ merge(Compressor.prototype, {
d.fixed = function() {
return iife.args[i] || make_node(AST_Undefined, iife);
};
- mark_as_safe(d);
+ mark(d, true);
});
}
if (node instanceof AST_If || node instanceof AST_DWLoop) {
@@ -373,29 +371,27 @@ merge(Compressor.prototype, {
});
this.walk(tw);
- function mark_as_safe(def) {
- safe_ids[safe_ids.length - 1][def.id] = true;
+ function mark(def, safe) {
+ safe_ids[def.id] = safe;
}
function is_safe(def) {
- for (var i = safe_ids.length, id = def.id; --i >= 0;) {
- if (safe_ids[i][id]) {
- if (def.fixed == null) {
- var orig = def.orig[0];
- if (orig instanceof AST_SymbolFunarg || orig.name == "arguments") return false;
- def.fixed = make_node(AST_Undefined, orig);
- }
- return true;
+ if (safe_ids[def.id]) {
+ if (def.fixed == null) {
+ var orig = def.orig[0];
+ if (orig instanceof AST_SymbolFunarg || orig.name == "arguments") return false;
+ def.fixed = make_node(AST_Undefined, orig);
}
+ return true;
}
}
function push() {
- safe_ids.push(Object.create(null));
+ safe_ids = Object.create(safe_ids);
}
function pop() {
- safe_ids.pop();
+ safe_ids = Object.getPrototypeOf(safe_ids);
}
function reset_def(def) {