fix corner case in `arguments` (#4411)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 18 Dec 2020 20:53:53 +0000 (20:53 +0000)
committerGitHub <noreply@github.com>
Fri, 18 Dec 2020 20:53:53 +0000 (04:53 +0800)
fixes #4410

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

index ab68c45..f33b97b 100644 (file)
@@ -9905,6 +9905,7 @@ merge(Compressor.prototype, {
             } else if (argname instanceof AST_Destructured) {
                 argname = null;
             } else if (argname && (compressor.has_directive("use strict")
+                || fn.name
                 || !(fn_parent instanceof AST_Call && index < fn_parent.args.length)
                 || !all(fn.argnames, function(argname) {
                     return !(argname instanceof AST_Destructured);
index c3ef226..39628b5 100644 (file)
@@ -871,3 +871,74 @@ issue_4397: {
     }
     expect_stdout: "string"
 }
+
+issue_4410_1: {
+    options = {
+        arguments: true,
+        conditionals: true,
+        evaluate: true,
+        reduce_vars: true,
+    }
+    input: {
+        (function(a) {
+            console.log(arguments[0] === (a = 0) ? "FAIL" : "PASS");
+        })(1);
+    }
+    expect: {
+        (function(a) {
+            console.log(a === (a = 0) ? "FAIL" : "PASS");
+        })(1);
+    }
+    expect_stdout: "PASS"
+}
+
+issue_4410_2: {
+    options = {
+        arguments: true,
+        conditionals: true,
+        evaluate: true,
+        reduce_vars: true,
+    }
+    input: {
+        (function f(a) {
+            console.log(arguments[0] === (a = 0) ? "FAIL" : "PASS");
+        })(1);
+    }
+    expect: {
+        (function f(a) {
+            console.log(arguments[0] === (a = 0) ? "FAIL" : "PASS");
+        })(1);
+    }
+    expect_stdout: "PASS"
+}
+
+issue_4410_3: {
+    options = {
+        arguments: true,
+    }
+    input: {
+        var a = 1;
+        (function f(b) {
+            a-- && f();
+            for (var c = 2; c--;)
+                switch (arguments[0]) {
+                  case b = 42:
+                  case 42:
+                    console.log("PASS");
+                }
+        })(null);
+    }
+    expect: {
+        var a = 1;
+        (function f(b) {
+            a-- && f();
+            for (var c = 2; c--;)
+                switch (arguments[0]) {
+                  case b = 42:
+                  case 42:
+                    console.log("PASS");
+                }
+        })(null);
+    }
+    expect_stdout: "PASS"
+}