From 9a5aede94147bf5769054fd933b1c15690915d25 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sat, 19 Dec 2020 12:47:46 +0800 Subject: [PATCH] fix corner case in `reduce_vars` & `unused` (#4414) fixes #4413 --- lib/scope.js | 1 + test/compress/drop-unused.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/scope.js b/lib/scope.js index 187309ca..fac673bc 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -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 diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index 1c9ab61f..d048707a 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -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" +} -- 2.34.1