fix corner case in `reduce_vars` (#4433)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 21 Dec 2020 06:03:18 +0000 (06:03 +0000)
committerGitHub <noreply@github.com>
Mon, 21 Dec 2020 06:03:18 +0000 (14:03 +0800)
fixes #4432

lib/compress.js
test/compress/arguments.js

index d532300..81fe886 100644 (file)
@@ -912,10 +912,16 @@ merge(Compressor.prototype, {
             init.walk(tw);
             if (init instanceof AST_Definitions) {
                 init.definitions[0].name.match_symbol(function(node) {
-                    if (node instanceof AST_SymbolDeclaration) node.definition().fixed = false;
+                    if (node instanceof AST_SymbolDeclaration) {
+                        var def = node.definition();
+                        def.assignments++;
+                        def.fixed = false;
+                    }
                 }, true);
-            } else if (init instanceof AST_SymbolRef) {
-                init.definition().fixed = false;
+            } else if (init instanceof AST_SymbolRef && !init.is_immutable()) {
+                var def = init.definition();
+                def.assignments++;
+                def.fixed = false;
             }
             this.body.walk(tw);
             pop(tw);
index 39628b5..ddf5695 100644 (file)
@@ -942,3 +942,23 @@ issue_4410_3: {
     }
     expect_stdout: "PASS"
 }
+
+issue_4432: {
+    options = {
+        arguments: true,
+        reduce_vars: true,
+    }
+    input: {
+        console.log(function(a) {
+            for (a in { FAIL: 42 });
+            return arguments[0];
+        }() || "PASS");
+    }
+    expect: {
+        console.log(function(a) {
+            for (a in { FAIL: 42 });
+            return arguments[0];
+        }() || "PASS");
+    }
+    expect_stdout: "PASS"
+}