compute `uses_arguments` correctly in `figure_out_scope()` (#2099)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 14 Jun 2017 19:28:26 +0000 (03:28 +0800)
committerGitHub <noreply@github.com>
Wed, 14 Jun 2017 19:28:26 +0000 (03:28 +0800)
fixes #2097

lib/scope.js
test/compress/functions.js

index ea43f75..82a935a 100644 (file)
@@ -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);
index 1359670..909a57d 100644 (file)
@@ -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"
+}