diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-10-18 17:09:43 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-18 17:09:43 +0800 |
commit | cd072317d08cc0d1a97f8bd295ee1138d608ae84 (patch) | |
tree | ad362037ff6ce39bdd2473a604654dadbf21ec29 | |
parent | 0785a15aceaee3f4a31d9693a4230cbf0477ea81 (diff) | |
download | tracifyjs-cd072317d08cc0d1a97f8bd295ee1138d608ae84.tar.gz tracifyjs-cd072317d08cc0d1a97f8bd295ee1138d608ae84.zip |
fix corner case in `unused` (#3496)
fixes #3495
-rw-r--r-- | lib/compress.js | 6 | ||||
-rw-r--r-- | test/compress/drop-unused.js | 19 |
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 4b0ceee4..33b62daa 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3629,6 +3629,7 @@ merge(Compressor.prototype, { return !(def.id in in_use_ids) || def.orig.length > 1; }; // pass 3: we should drop declarations not in_use + var unused_fn_names = []; var tt = new TreeTransformer(function(node, descend, in_list) { var parent = tt.parent(); if (drop_vars) { @@ -3656,7 +3657,7 @@ merge(Compressor.prototype, { } if (scope !== self) return; if (node instanceof AST_Function && node.name && drop_fn_name(node.name.definition())) { - node.name = null; + unused_fn_names.push(node); } if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) { var trim = compressor.drop_fargs(node, parent); @@ -3853,6 +3854,9 @@ merge(Compressor.prototype, { }); tt.push(compressor.parent()); self.transform(tt); + unused_fn_names.forEach(function(fn) { + fn.name = null; + }); function verify_safe_usage(def, read, modified) { if (def.id in in_use_ids) return; diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index 6ed193e9..ea7ee02f 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -2062,3 +2062,22 @@ issue_3427_2: { } expect_stdout: "PASS" } + +issue_3495: { + options = { + dead_code: true, + pure_getters: "strict", + side_effects: true, + unused: true, + } + input: { + console.log(function f() { + f = 0; + var a = f.p; + }()); + } + expect: { + console.log(void 0); + } + expect_stdout: "undefined" +} |