From aff842f2f9311295877de7e22c3c6afa4f82214b Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 18 Nov 2020 00:54:58 +0000 Subject: [PATCH] fix corner case in `arguments` (#4293) fixes #4291 --- lib/compress.js | 3 ++- lib/scope.js | 6 +++++- test/compress/arguments.js | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 9adcec8c..c1da6e77 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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 = []; diff --git a/lib/scope.js b/lib/scope.js index bffd493d..0e44280f 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -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(); diff --git a/test/compress/arguments.js b/test/compress/arguments.js index a835aef8..37307ed5 100644 --- a/test/compress/arguments.js +++ b/test/compress/arguments.js @@ -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" +} -- 2.34.1