From 3f961bbba04a8cec0ab74f4a13deb4be217da877 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 15 Jun 2017 03:28:26 +0800 Subject: [PATCH] compute `uses_arguments` correctly in `figure_out_scope()` (#2099) fixes #2097 --- lib/scope.js | 5 ++--- test/compress/functions.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/scope.js b/lib/scope.js index ea43f752..82a935a2 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -197,11 +197,10 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ } } var sym = node.scope.find_variable(name); - if (node.scope instanceof AST_Lambda && name == "arguments") { - node.scope.uses_arguments = true; - } if (!sym) { sym = self.def_global(node); + } else if (sym.scope instanceof AST_Lambda && name == "arguments") { + sym.scope.uses_arguments = true; } node.thedef = sym; node.reference(options); diff --git a/test/compress/functions.js b/test/compress/functions.js index 1359670e..909a57dd 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -336,3 +336,32 @@ issue_2084: { } expect_stdout: "0" } + +issue_2097: { + options = { + negate_iife: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + function f() { + try { + throw 0; + } catch (e) { + console.log(arguments[0]); + } + } + f(1); + } + expect: { + !function() { + try { + throw 0; + } catch (e) { + console.log(arguments[0]); + } + }(1); + } + expect_stdout: "1" +} -- 2.34.1