fix corner case in `reduce_vars` & `unused` (#4414)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 19 Dec 2020 04:47:46 +0000 (12:47 +0800)
committerGitHub <noreply@github.com>
Sat, 19 Dec 2020 04:47:46 +0000 (12:47 +0800)
fixes #4413

lib/scope.js
test/compress/drop-unused.js

index 187309c..fac673b 100644 (file)
@@ -257,6 +257,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
                 sym = self.def_global(node);
             } else if (name == "arguments"
                 && sym.orig[0] instanceof AST_SymbolFunarg
+                && !(sym.orig[1] instanceof AST_SymbolFunarg)
                 && !(sym.scope instanceof AST_Arrow)) {
                 var parent = tw.parent();
                 if (parent instanceof AST_Assign && parent.left === node
index 1c9ab61..d048707 100644 (file)
@@ -3134,3 +3134,22 @@ issue_4404: {
     }
     expect_stdout: "PASS"
 }
+
+issue_4413: {
+    options = {
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        console.log(function f(arguments) {
+            var arguments = function() {};
+            return arguments.length;
+        }());
+    }
+    expect: {
+        console.log(function(arguments) {
+            return function() {}.length;
+        }());
+    }
+    expect_stdout: "0"
+}