diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-11-18 00:54:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-18 08:54:58 +0800 |
commit | aff842f2f9311295877de7e22c3c6afa4f82214b (patch) | |
tree | 55793b02a14e25c760928c86bf85d37b4d403785 | |
parent | 0bedd031da4fa8f0eef0fbe6737aa3a4c156a61e (diff) | |
download | tracifyjs-aff842f2f9311295877de7e22c3c6afa4f82214b.tar.gz tracifyjs-aff842f2f9311295877de7e22c3c6afa4f82214b.zip |
fix corner case in `arguments` (#4293)
fixes #4291
-rw-r--r-- | lib/compress.js | 3 | ||||
-rw-r--r-- | lib/scope.js | 6 | ||||
-rw-r--r-- | 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" +} |