fix corner case in `evaluate` & `reduce_vars` (#4394)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 17 Dec 2020 23:16:04 +0000 (23:16 +0000)
committerGitHub <noreply@github.com>
Thu, 17 Dec 2020 23:16:04 +0000 (07:16 +0800)
fixes #4393

lib/compress.js
test/compress/evaluate.js

index fa59ef5..b8f4b3a 100644 (file)
@@ -426,6 +426,9 @@ merge(Compressor.prototype, {
                     }
                 });
             };
+            if (scope.uses_arguments) scope.each_argname(function(node) {
+                node.definition().last_ref = false;
+            });
             if (compressor.option("ie8")) scope.variables.each(function(def) {
                 var d = def.orig[0].definition();
                 if (d !== def) d.fixed = false;
@@ -479,7 +482,7 @@ merge(Compressor.prototype, {
 
         function push_ref(def, ref) {
             def.references.push(ref);
-            def.last_ref = ref;
+            if (def.last_ref !== false) def.last_ref = ref;
         }
 
         function safe_to_read(tw, def) {
index 46a92ee..8ef1a46 100644 (file)
@@ -3074,3 +3074,23 @@ issue_4271: {
         "PASS",
     ]
 }
+
+issue_4393: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+    }
+    input: {
+        (function f(a) {
+            a = "PASS";
+            console.log(arguments[0]);
+        })("FAIL");
+    }
+    expect: {
+        (function f(a) {
+            a = "PASS";
+            console.log(arguments[0]);
+        })("FAIL");
+    }
+    expect_stdout: "PASS"
+}