fix corner case in `hoist_props` (#3947)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 2 Jun 2020 15:51:06 +0000 (16:51 +0100)
committerGitHub <noreply@github.com>
Tue, 2 Jun 2020 15:51:06 +0000 (23:51 +0800)
fixes #3945

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

index cfe37d0..f3fc5e0 100644 (file)
@@ -5074,6 +5074,9 @@ merge(Compressor.prototype, {
                 && right.properties.length > 0
                 && all(right.properties, function(prop) {
                     return prop instanceof AST_ObjectKeyVal;
+                })
+                && all(def.references, function(ref) {
+                    return ref.fixed_value() === right;
                 });
         }
     });
index a73df1f..4fcbd79 100644 (file)
@@ -972,3 +972,26 @@ issue_3871: {
     }
     expect_stdout: "PASS"
 }
+
+issue_3945: {
+    options = {
+        hoist_props: true,
+        reduce_vars: true,
+    }
+    input: {
+        function f() {
+            o.p;
+            var o = {
+                q: 0,
+            };
+        }
+    }
+    expect: {
+        function f() {
+            o.p;
+            var o = {
+                q: 0,
+            };
+        }
+    }
+}