fix corner case in `reduce_vars` (#4219)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 13 Oct 2020 23:58:04 +0000 (00:58 +0100)
committerGitHub <noreply@github.com>
Tue, 13 Oct 2020 23:58:04 +0000 (07:58 +0800)
fixes #4218

lib/compress.js
test/compress/const.js

index b2ed17c..3e6218a 100644 (file)
@@ -993,6 +993,7 @@ merge(Compressor.prototype, {
                     return node.value;
                 };
                 d.fixed.assigns = [ node ];
+                if (node.name instanceof AST_SymbolConst && d.redefined()) d.single_use = false;
             } else {
                 d.fixed = false;
             }
index 27c55dd..8c04c6b 100644 (file)
@@ -931,6 +931,30 @@ issue_4207: {
     expect_stdout: "0"
 }
 
+issue_4218: {
+    options = {
+        reduce_funcs: true,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        {
+            const a = function() {};
+            var b = 0 * a;
+        }
+        console.log(typeof a, b);
+    }
+    expect: {
+        {
+            const a = function() {};
+            var b = 0 * a;
+        }
+        console.log(typeof a, b);
+    }
+    expect_stdout: true
+}
+
 issue_4210: {
     options = {
         reduce_vars: true,