fix corner case in `inline` (#5231)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 23 Dec 2021 06:26:07 +0000 (06:26 +0000)
committerGitHub <noreply@github.com>
Thu, 23 Dec 2021 06:26:07 +0000 (14:26 +0800)
fixes #5230

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

index 5a8f9ad..b48d7bc 100644 (file)
@@ -10245,7 +10245,9 @@ Compressor.prototype.compress = function(node) {
                 if (stat instanceof AST_LambdaDefinition) {
                     if (in_loop) {
                         var name = make_node(AST_SymbolVar, stat.name, flatten_var(stat.name));
-                        name.definition().orig.push(name);
+                        var def = name.definition();
+                        def.fixed = false;
+                        def.orig.push(name);
                         append_var(decls, expressions, name, to_func_expr(stat, true));
                     } else {
                         var def = stat.name.definition();
index e9c2547..0273519 100644 (file)
@@ -7071,3 +7071,35 @@ issue_5173_2: {
     }
     expect_stdout: "undefined"
 }
+
+issue_5230: {
+    options = {
+        collapse_vars: true,
+        inline: true,
+        merge_vars: true,
+        reduce_vars: true,
+        side_effects: true,
+        toplevel: true,
+    }
+    input: {
+        while (function() {
+            function f(a) {
+                var b = 42, c = (console, [ a ]);
+                for (var k in c)
+                    c, console.log(b++);
+            }
+            f(f);
+        }());
+    }
+    expect: {
+        while (void (f = function(c) {
+            var b = 42;
+            console;
+            var c;
+            for (var k in c = [ c ])
+                console.log(b++);
+        })(f));
+        var f;
+    }
+    expect_stdout: "42"
+}