aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-05-13 02:26:57 +0100
committerGitHub <noreply@github.com>2021-05-13 09:26:57 +0800
commite04429350f4eff1299afe84967d15093abc091ff (patch)
treeecd07bafb17145b50d4c8f825f36918cfc0deb92 /lib/compress.js
parent60f3b5515675644cde8ef1a980295f5c841956d8 (diff)
downloadtracifyjs-e04429350f4eff1299afe84967d15093abc091ff.tar.gz
tracifyjs-e04429350f4eff1299afe84967d15093abc091ff.zip
fix corner case in `ie8` (#4929)
fixes #4928
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js36
1 files changed, 24 insertions, 12 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 9d83fc09..38e76620 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -6092,6 +6092,30 @@ merge(Compressor.prototype, {
});
tw.directives = Object.create(compressor.directives);
self.walk(tw);
+ var drop_fn_name = compressor.option("keep_fnames") ? return_false : compressor.option("ie8") ? function(def) {
+ return !compressor.exposed(def) && def.references.length == def.replaced;
+ } : function(def) {
+ if (!(def.id in in_use_ids)) return true;
+ if (def.orig.length < 2) return false;
+ // function argument will always overshadow its name
+ if (def.orig[1] instanceof AST_SymbolFunarg) return true;
+ // retain if referenced within destructured object of argument
+ return all(def.references, function(ref) {
+ return !ref.in_arg;
+ });
+ };
+ if (compressor.option("ie8")) initializations.each(function(init, id) {
+ if (id in in_use_ids) return;
+ init.forEach(function(init) {
+ init.walk(new TreeWalker(function(node) {
+ if (node instanceof AST_Function && node.name && !drop_fn_name(node.name.definition())) {
+ node.walk(tw);
+ return true;
+ }
+ if (node instanceof AST_Scope) return true;
+ }));
+ });
+ });
// pass 2: for every used symbol we need to walk its
// initialization code to figure out if it uses other
// symbols (that may not be in_use).
@@ -6129,18 +6153,6 @@ merge(Compressor.prototype, {
delete assign_in_use[id];
}
});
- var drop_fn_name = compressor.option("keep_fnames") ? return_false : compressor.option("ie8") ? function(def) {
- return !compressor.exposed(def) && def.references.length == def.replaced;
- } : function(def) {
- if (!(def.id in in_use_ids)) return true;
- if (def.orig.length < 2) return false;
- // function argument will always overshadow its name
- if (def.orig[1] instanceof AST_SymbolFunarg) return true;
- // retain if referenced within destructured object of argument
- return all(def.references, function(ref) {
- return !ref.in_arg;
- });
- };
// pass 3: we should drop declarations not in_use
var trim_defns = [];
var unused_fn_names = [];