fix corner case in `collapse_vars` (#5169)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 13 Nov 2021 14:18:18 +0000 (14:18 +0000)
committerGitHub <noreply@github.com>
Sat, 13 Nov 2021 14:18:18 +0000 (22:18 +0800)
fixes #5168

lib/compress.js
test/compress/destructured.js

index d8823d6..351ec2f 100644 (file)
@@ -1501,7 +1501,7 @@ merge(Compressor.prototype, {
 
     AST_SymbolRef.DEFMETHOD("is_immutable", function() {
         var def = this.redef || this.definition();
-        return def.orig.length == 1 && def.orig[0] instanceof AST_SymbolLambda;
+        return (this.in_arg || def.orig.length == 1) && def.orig[0] instanceof AST_SymbolLambda;
     });
 
     AST_Node.DEFMETHOD("convert_symbol", noop);
@@ -3369,10 +3369,10 @@ merge(Compressor.prototype, {
                 }
             }
             statements.length = n;
-            CHANGED = n != len;
             if (has_quit) has_quit.forEach(function(stat) {
                 extract_declarations_from_unreachable_code(compressor, stat, statements);
             });
+            CHANGED = statements.length != len;
         }
 
         function sequencesize(statements, compressor) {
index 87d7e1b..9731f0e 100644 (file)
@@ -3225,3 +3225,31 @@ issue_5153_object_var: {
     expect_stdout: "PASS"
     node_version: ">=6"
 }
+
+issue_5168: {
+    options = {
+        collapse_vars: true,
+    }
+    input: {
+        (function a({
+            [console.log(typeof function() {
+                ++a;
+                return a;
+            }())]: b,
+        }) {
+            var a;
+        })({});
+    }
+    expect: {
+        (function a({
+            [console.log(typeof function() {
+                ++a;
+                return a;
+            }())]: b,
+        }) {
+            var a;
+        })({});
+    }
+    expect_stdout: "function"
+    node_version: ">=6"
+}