fix corner case in `arguments` (#3939)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sun, 31 May 2020 04:18:27 +0000 (05:18 +0100)
committerGitHub <noreply@github.com>
Sun, 31 May 2020 04:18:27 +0000 (12:18 +0800)
lib/compress.js
test/compress/arguments.js

index 0791632..adae933 100644 (file)
@@ -8322,7 +8322,8 @@ merge(Compressor.prototype, {
             var argname = fn.argnames[index];
             if (def.deleted && def.deleted[index]) {
                 argname = null;
-            } else if (argname && compressor.has_directive("use strict")) {
+            } else if (argname && (compressor.has_directive("use strict")
+                || !(fn_parent instanceof AST_Call && index < fn_parent.args.length))) {
                 var arg_def = argname.definition();
                 if (!compressor.option("reduce_vars")
                     || def.reassigned
index 119eaf2..dc00eef 100644 (file)
@@ -243,20 +243,18 @@ issue_3273: {
         arguments: true,
     }
     input: {
-        function f(a) {
+        (function(a) {
             console.log(arguments[0], a);
             arguments[0]++;
             console.log(arguments[0], a);
-        }
-        f(0);
+        })(0);
     }
     expect: {
-        function f(a) {
+        (function(a) {
             console.log(a, a);
             a++;
             console.log(a, a);
-        }
-        f(0);
+        })(0);
     }
     expect_stdout: [
         "0 0",
@@ -264,26 +262,43 @@ issue_3273: {
     ]
 }
 
+issue_3273_no_call_arg: {
+    options = {
+        arguments: true,
+    }
+    input: {
+        (function(a) {
+            arguments[0] = "FAIL";
+            console.log(a);
+        })();
+    }
+    expect: {
+        (function(a) {
+            arguments[0] = "FAIL";
+            console.log(a);
+        })();
+    }
+    expect_stdout: "undefined"
+}
+
 issue_3273_reduce_vars: {
     options = {
         arguments: true,
         reduce_vars: true,
     }
     input: {
-        function f(a) {
+        (function(a) {
             console.log(arguments[0], a);
             arguments[0]++;
             console.log(arguments[0], a);
-        }
-        f(0);
+        })(0);
     }
     expect: {
-        function f(a) {
+        (function(a) {
             console.log(a, a);
             a++;
             console.log(a, a);
-        }
-        f(0);
+        })(0);
     }
     expect_stdout: [
         "0 0",
@@ -296,22 +311,20 @@ issue_3273_local_strict: {
         arguments: true,
     }
     input: {
-        function f(a) {
+        (function(a) {
             "use strict";
             console.log(arguments[0], a);
             arguments[0]++;
             console.log(arguments[0], a);
-        }
-        f(0);
+        })(0);
     }
     expect: {
-        function f(a) {
+        (function(a) {
             "use strict";
             console.log(arguments[0], a);
             arguments[0]++;
             console.log(arguments[0], a);
-        }
-        f(0);
+        })(0);
     }
     expect_stdout: [
         "0 0",
@@ -325,22 +338,20 @@ issue_3273_local_strict_reduce_vars: {
         reduce_vars: true,
     }
     input: {
-        function f(a) {
+        (function(a) {
             "use strict";
             console.log(arguments[0], a);
             arguments[0]++;
             console.log(arguments[0], a);
-        }
-        f(0);
+        })(0);
     }
     expect: {
-        function f(a) {
+        (function(a) {
             "use strict";
             console.log(arguments[0], a);
             arguments[0]++;
             console.log(arguments[0], a);
-        }
-        f(0);
+        })(0);
     }
     expect_stdout: [
         "0 0",
@@ -354,21 +365,19 @@ issue_3273_global_strict: {
     }
     input: {
         "use strict";
-        function f(a) {
+        (function(a) {
             console.log(arguments[0], a);
             arguments[0]++;
             console.log(arguments[0], a);
-        }
-        f(0);
+        })(0);
     }
     expect: {
         "use strict";
-        function f(a) {
+        (function(a) {
             console.log(arguments[0], a);
             arguments[0]++;
             console.log(arguments[0], a);
-        }
-        f(0);
+        })(0);
     }
     expect_stdout: [
         "0 0",
@@ -383,21 +392,19 @@ issue_3273_global_strict_reduce_vars: {
     }
     input: {
         "use strict";
-        function f(a) {
+        (function(a) {
             console.log(arguments[0], a);
             arguments[0]++;
             console.log(arguments[0], a);
-        }
-        f(0);
+        })(0);
     }
     expect: {
         "use strict";
-        function f(a) {
+        (function(a) {
             console.log(arguments[0], a);
             arguments[0]++;
             console.log(arguments[0], a);
-        }
-        f(0);
+        })(0);
     }
     expect_stdout: [
         "0 0",