fix corner case in `hoist_props` (#3022)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 22 Mar 2018 23:27:35 +0000 (07:27 +0800)
committerGitHub <noreply@github.com>
Thu, 22 Mar 2018 23:27:35 +0000 (07:27 +0800)
fixes #3021

lib/compress.js
test/compress/hoist_props.js

index 972341b..03ed9e8 100644 (file)
@@ -3624,8 +3624,9 @@ merge(Compressor.prototype, {
                 var sym = node.name, def, value;
                 if (sym.scope === self
                     && (def = sym.definition()).escaped != 1
-                    && !def.single_use
+                    && !def.assignments
                     && !def.direct_access
+                    && !def.single_use
                     && !top_retain(def)
                     && (value = sym.fixed_value()) === node.value
                     && value instanceof AST_Object) {
index 26887af..90a7f1d 100644 (file)
@@ -686,3 +686,33 @@ undefined_key: {
     }
     expect_stdout: "3"
 }
+
+issue_3021: {
+    options = {
+        hoist_props: true,
+        reduce_vars: true,
+    }
+    input: {
+        var a = 1, b = 2;
+        (function() {
+            b = a;
+            if (a++ + b--)
+                return 1;
+            return;
+            var b = {};
+        })();
+        console.log(a, b);
+    }
+    expect: {
+        var a = 1, b = 2;
+        (function() {
+            b = a;
+            if (a++ + b--)
+                return 1;
+            return;
+            var b = {};
+        })();
+        console.log(a, b);
+    }
+    expect_stdout: "2 2"
+}