enhance `reduce_vars` (#4479)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 29 Dec 2020 11:43:12 +0000 (11:43 +0000)
committerGitHub <noreply@github.com>
Tue, 29 Dec 2020 11:43:12 +0000 (19:43 +0800)
lib/compress.js
test/compress/let.js

index 0369b63..591ad4d 100644 (file)
@@ -771,8 +771,7 @@ merge(Compressor.prototype, {
                     }
                     var d = sym.definition();
                     d.assignments++;
-                    if (!is_modified(compressor, tw, node, node.right, 0)
-                        && can_drop_symbol(sym) && safe_to_assign(tw, d)) {
+                    if (!is_modified(compressor, tw, node, node.right, 0) && safe_to_assign(tw, d)) {
                         push_ref(d, sym);
                         mark(tw, d);
                         if (d.single_use && left instanceof AST_Destructured) d.single_use = false;
index 59b8902..f52dcb5 100644 (file)
@@ -359,6 +359,28 @@ reduce_block_2_toplevel: {
     node_version: ">=4"
 }
 
+reduce_vars: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        "use strict";
+        let a = "PASS";
+        console.log(a);
+        a = "FAIL";
+    }
+    expect: {
+        "use strict";
+        console.log("PASS");
+        "FAIL";
+    }
+    expect_stdout: "PASS"
+    node_version: ">=4"
+}
+
 hoist_props: {
     options = {
         hoist_props: true,