fix corner case in `join_vars` (#3917)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 21 May 2020 21:26:46 +0000 (22:26 +0100)
committerGitHub <noreply@github.com>
Thu, 21 May 2020 21:26:46 +0000 (05:26 +0800)
fixes #3916

lib/compress.js
test/compress/join_vars.js

index 06d04cc..17eeb87 100644 (file)
@@ -2508,7 +2508,7 @@ merge(Compressor.prototype, {
                 }
                 if (prop instanceof AST_Node) break;
                 prop = "" + prop;
-                var diff = compressor.has_directive("use strict") ? function(node) {
+                var diff = prop == "__proto__" || compressor.has_directive("use strict") ? function(node) {
                     return node.key != prop && node.key.name != prop;
                 } : function(node) {
                     return node.key.name != prop;
index 67d7fd0..590f997 100644 (file)
@@ -1023,3 +1023,35 @@ issue_3856: {
     }
     expect_stdout: "undefined"
 }
+
+issue_3916: {
+    options = {
+        join_vars: true,
+    }
+    input: {
+        var o = {};
+        o.p = "PASS";
+        o.__proto__ = 42;
+        o.q = "FAIL";
+        o.__proto__ = {
+            p: "FAIL",
+            q: "PASS",
+        };
+        o.__proto__ = "foo";
+        console.log(typeof o.__proto__, o.p, delete o.q, o.q);
+    }
+    expect: {
+        var o = {
+            p: "PASS",
+            __proto__: 42,
+            q: "FAIL",
+        };
+        o.__proto__ = {
+            p: "FAIL",
+            q: "PASS",
+        };
+        o.__proto__ = "foo";
+        console.log(typeof o.__proto__, o.p, delete o.q, o.q);
+    }
+    expect_stdout: "object PASS true PASS"
+}