aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-10-05 16:51:16 +0300
committerMihai Bazon <mihai@bazon.net>2012-10-05 16:51:16 +0300
commita1e088593068a59ea7e620dc0cf412f1c01caa86 (patch)
tree3b11fd8361374d12e97a02315fb11695f3fba1e1 /lib
parent7ae09120ed5080ef09760def08dd7803ec977b1b (diff)
downloadtracifyjs-a1e088593068a59ea7e620dc0cf412f1c01caa86.tar.gz
tracifyjs-a1e088593068a59ea7e620dc0cf412f1c01caa86.zip
replace `(function(){ ...no side effects ... })()` with `undefined`.
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js
index fcf022e1..a4ac691a 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -673,16 +673,19 @@ merge(Compressor.prototype, {
def(AST_EmptyStatement, function(){ return false });
def(AST_Constant, function(){ return false });
def(AST_This, function(){ return false });
- def(AST_Function, function(){ return false });
- def(AST_BlockStatement, function(){
+
+ function block(){
for (var i = this.body.length; --i >= 0;) {
if (this.body[i].has_side_effects())
return true;
}
return false;
- });
+ };
+ def(AST_Block, block);
+ def(AST_BlockStatement, block);
def(AST_SimpleStatement, function(){
+ if (this.body instanceof AST_Function) return false;
return this.body.has_side_effects();
});
def(AST_Binary, function(){
@@ -1281,6 +1284,13 @@ merge(Compressor.prototype, {
});
}
}
+ if (compressor.option("side_effects")) {
+ if (self.expression instanceof AST_Function
+ && self.args.length == 0
+ && !self.expression.has_side_effects()) {
+ return make_node(AST_Undefined, self);
+ }
+ }
return self;
});