fix corner case in `arguments` (#4293)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 18 Nov 2020 00:54:58 +0000 (00:54 +0000)
committerGitHub <noreply@github.com>
Wed, 18 Nov 2020 00:54:58 +0000 (08:54 +0800)
fixes #4291

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

index 9adcec8..c1da6e7 100644 (file)
@@ -9575,7 +9575,8 @@ merge(Compressor.prototype, {
             && expr instanceof AST_SymbolRef
             && is_arguments(def = expr.definition())
             && prop instanceof AST_Number
-            && (fn = expr.scope.resolve()) === find_lambda()) {
+            && (fn = expr.scope.resolve()) === find_lambda()
+            && fn.uses_arguments !== "d") {
             var index = prop.value;
             if (parent instanceof AST_UnaryPrefix && parent.operator == "delete") {
                 if (!def.deleted) def.deleted = [];
index bffd493..0e44280 100644 (file)
@@ -235,7 +235,11 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
             if (!sym) {
                 sym = self.def_global(node);
             } else if (name == "arguments" && sym.scope instanceof AST_Lambda) {
-                sym.scope.uses_arguments = true;
+                if (!(tw.parent() instanceof AST_PropAccess)) {
+                    sym.scope.uses_arguments = "d";
+                } else if (!sym.scope.uses_arguments) {
+                    sym.scope.uses_arguments = true;
+                }
             }
             if (name == "eval") {
                 var parent = tw.parent();
index a835aef..37307ed 100644 (file)
@@ -807,3 +807,23 @@ issue_4200: {
     }
     expect_stdout: "undefined"
 }
+
+issue_4291: {
+    options = {
+        arguments: true,
+        keep_fargs: "strict",
+    }
+    input: {
+        console.log(function() {
+            arguments[0] = "PASS";
+            return arguments;
+        }()[0]);
+    }
+    expect: {
+        console.log(function() {
+            arguments[0] = "PASS";
+            return arguments;
+        }()[0]);
+    }
+    expect_stdout: "PASS"
+}