aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-10-24 06:33:48 +0100
committerGitHub <noreply@github.com>2020-10-24 13:33:48 +0800
commitc5df8355ba00fdf5ffa81192e0d88cf0dca90061 (patch)
treeaf48bda48ba5fd71857ec9d28d1e08f3bd78d40f
parentff38d2471f36815f3d56774092a8d298719fd4fb (diff)
downloadtracifyjs-c5df8355ba00fdf5ffa81192e0d88cf0dca90061.tar.gz
tracifyjs-c5df8355ba00fdf5ffa81192e0d88cf0dca90061.zip
fix corner case in `loops` & `unused` (#4241)
fixes #4240
-rw-r--r--lib/compress.js2
-rw-r--r--test/compress/loops.js32
2 files changed, 33 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index c6e27e06..216ca92a 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -5182,7 +5182,7 @@ merge(Compressor.prototype, {
var def = sym.definition();
if (!def) return;
if (def.id in in_use_ids) return;
- if (def.scope !== self && member(def, self.enclosed)) return;
+ if (def.scope !== self && self.find_variable(sym) === def) return;
log(sym, "Dropping unused loop variable {name}");
if (for_ins[def.id] === node) delete for_ins[def.id];
var body = [];
diff --git a/test/compress/loops.js b/test/compress/loops.js
index cfabe6fd..69150820 100644
--- a/test/compress/loops.js
+++ b/test/compress/loops.js
@@ -1222,3 +1222,35 @@ do_continue: {
}
expect_stdout: "PASS"
}
+
+issue_4240: {
+ options = {
+ loops: true,
+ reduce_funcs: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ (function(a) {
+ function f() {
+ var o = { PASS: 42 };
+ for (a in o);
+ }
+ (function() {
+ if (f());
+ })();
+ console.log(a);
+ })();
+ }
+ expect: {
+ (function(a) {
+ (function() {
+ if (function() {
+ for (a in { PASS: 42 });
+ }());
+ })();
+ console.log(a);
+ })();
+ }
+ expect_stdout: "PASS"
+}