fix corner case in `merge_vars`
authoralexlamsl <alexlamsl@gmail.com>
Mon, 21 Sep 2020 21:03:06 +0000 (05:03 +0800)
committeralexlamsl <alexlamsl@gmail.com>
Mon, 21 Sep 2020 21:03:06 +0000 (05:03 +0800)
fixes #4139

lib/compress.js
test/compress/merge_vars.js

index 82bbbf1..30a82e3 100644 (file)
@@ -4408,12 +4408,9 @@ merge(Compressor.prototype, {
             if (node instanceof AST_Scope) {
                 push();
                 segment.block = node;
-                if (node instanceof AST_Lambda) {
-                    if (node.name) {
-                        if (node !== self) segment.loop = true;
-                        references[node.name.definition().id] = false;
-                    }
-                    references[node.variables.get("arguments").id] = false;
+                if (node instanceof AST_Lambda && node.name) {
+                    if (node !== self) segment.loop = true;
+                    references[node.name.definition().id] = false;
                 }
                 descend();
                 pop();
@@ -4533,6 +4530,7 @@ merge(Compressor.prototype, {
         }
 
         function mark(sym, read, write) {
+            if (sym.name == "arguments") return;
             var def = sym.definition();
             if (def.id in references) {
                 var refs = references[def.id];
index b5b7101..559832c 100644 (file)
@@ -2738,3 +2738,31 @@ issue_4135: {
     }
     expect_stdout: "1 -1 undefined"
 }
+
+issue_4139: {
+    options = {
+        merge_vars: true,
+        toplevel: true,
+    }
+    input: {
+        try {
+            console.log;
+        } catch (e) {
+            var a, arguments = 0;
+        } finally {
+            a = typeof arguments;
+            console.log(a);
+        }
+    }
+    expect: {
+        try {
+            console.log;
+        } catch (e) {
+            var a, arguments = 0;
+        } finally {
+            a = typeof arguments;
+            console.log(a);
+        }
+    }
+    expect_stdout: "object"
+}