suppress `unsafe_proto` for LHS expressions (#2804)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 17 Jan 2018 12:41:51 +0000 (20:41 +0800)
committerGitHub <noreply@github.com>
Wed, 17 Jan 2018 12:41:51 +0000 (20:41 +0800)
lib/compress.js
test/compress/properties.js

index 5fd49cf..6417822 100644 (file)
@@ -5644,6 +5644,7 @@ merge(Compressor.prototype, {
         if (def) {
             return def.optimize(compressor);
         }
+        if (is_lhs(self, compressor.parent())) return self;
         if (compressor.option("unsafe_proto")
             && self.expression instanceof AST_Dot
             && self.expression.property == "prototype") {
@@ -5682,7 +5683,6 @@ merge(Compressor.prototype, {
                 break;
             }
         }
-        if (is_lhs(self, compressor.parent())) return self;
         var sub = self.flatten_object(self.property, compressor);
         if (sub) return sub.optimize(compressor);
         var ev = self.evaluate(compressor);
index 933774d..af115ff 100644 (file)
@@ -583,6 +583,25 @@ native_prototype: {
     }
 }
 
+native_prototype_lhs: {
+    options = {
+        unsafe_proto: true,
+    }
+    input: {
+        console.log(function() {
+            Function.prototype.bar = "PASS";
+            return function() {};
+        }().bar);
+    }
+    expect: {
+        console.log(function() {
+            Function.prototype.bar = "PASS";
+            return function() {};
+        }().bar);
+    }
+    expect_stdout: "PASS"
+}
+
 accessor_boolean: {
     input: {
         var a = 1;