aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index a2acd53f..76eb6918 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4307,6 +4307,17 @@ merge(Compressor.prototype, {
return self;
});
+ AST_Lambda.DEFMETHOD("contains_this", function() {
+ var result;
+ var self = this;
+ self.walk(new TreeWalker(function(node) {
+ if (result) return true;
+ if (node instanceof AST_This) return result = true;
+ if (node !== self && node instanceof AST_Scope) return true;
+ }));
+ return result;
+ });
+
OPT(AST_Dot, function(self, compressor){
var def = self.resolve_defines(compressor);
if (def) {
@@ -4321,6 +4332,20 @@ merge(Compressor.prototype, {
})
}).optimize(compressor);
}
+ if (compressor.option("unsafe") && self.expression instanceof AST_Object) {
+ var values = self.expression.properties;
+ for (var i = values.length; --i >= 0;) {
+ if (values[i].key === prop) {
+ var value = values[i].value;
+ if (value instanceof AST_Function ? !value.contains_this() : !value.has_side_effects(compressor)) {
+ var obj = self.expression.clone();
+ obj.properties = obj.properties.slice();
+ obj.properties.splice(i, 1);
+ return make_sequence(self, [ obj, value ]).optimize(compressor);
+ }
+ }
+ }
+ }
if (compressor.option("unsafe_proto")
&& self.expression instanceof AST_Dot
&& self.expression.property == "prototype") {