From d3ce2bc9e73d9d98b34b261d282a18b9ce9d5880 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 17 Jan 2018 20:41:51 +0800 Subject: [PATCH] suppress `unsafe_proto` for LHS expressions (#2804) --- lib/compress.js | 2 +- test/compress/properties.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 5fd49cf1..64178227 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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); diff --git a/test/compress/properties.js b/test/compress/properties.js index 933774d5..af115ff1 100644 --- a/test/compress/properties.js +++ b/test/compress/properties.js @@ -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; -- 2.34.1