fix corner case in `reduce_vars` (#3341)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 15 Mar 2019 08:06:47 +0000 (16:06 +0800)
committerGitHub <noreply@github.com>
Fri, 15 Mar 2019 08:06:47 +0000 (16:06 +0800)
lib/compress.js
test/compress/reduce_vars.js

index 43fd561..1aa7556 100644 (file)
@@ -5833,7 +5833,7 @@ merge(Compressor.prototype, {
                             var fn = node.fixed_value();
                             if (!(fn instanceof AST_Lambda)) return;
                             if (!fn.name) return;
-                            if (!fixed.variables.get(fn.name.name)) return;
+                            if (fixed.variables.get(fn.name.name) !== fn.name.definition()) return;
                             fn.name = fn.name.clone();
                             var value_def = value.variables.get(fn.name.name) || value.def_function(fn.name);
                             node.thedef = value_def;
index 32a06b1..27e5345 100644 (file)
@@ -6686,3 +6686,33 @@ issues_3267_3: {
     }
     expect_stdout: "PASS"
 }
+
+issue_3297: {
+    options = {
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        (function() {
+            function f() {
+                var a;
+                var b = function a() {
+                    console.log(a === b) && f();
+                };
+                b();
+            }
+            f();
+        })();
+    }
+    expect: {
+        (function() {
+            (function f() {
+                var b = function a() {
+                    console.log(a === b) && f();
+                };
+                b();
+            })();
+        })();
+    }
+    expect_stdout: "true"
+}