Preserve program completion value with enable_iife enabled

Fix #640
This commit is contained in:
Richard van Velzen 2016-09-16 12:45:29 +02:00
parent 7d8dea3b26
commit 29e1ff0981
2 changed files with 25 additions and 3 deletions

View File

@ -838,6 +838,14 @@ merge(Compressor.prototype, {
return false;
}
function is_completion_statement(node) {
if (compressor.parent()) {
return false;
}
return statements[statements.length - 1].body === node;
}
statements.forEach(function(stat){
if (stat instanceof AST_SimpleStatement) {
stat.body = (function transform(thing) {
@ -846,6 +854,8 @@ merge(Compressor.prototype, {
return node;
}
if (is_iife_call(node)) {
if (is_completion_statement(node)) return node;
return make_node(AST_UnaryPrefix, node, {
operator: "!",
expression: node

View File

@ -6,7 +6,7 @@ negate_iife_1: {
(function(){ stuff() })();
}
expect: {
!function(){ stuff() }();
(function(){ stuff() })();
}
}
@ -156,7 +156,7 @@ issue_1254_negate_iife_true: {
};
})()();
}
expect_exact: '!function(){return function(){console.log("test")}}()();'
expect_exact: '(function(){return function(){console.log("test")}})()();'
}
issue_1254_negate_iife_nested: {
@ -170,5 +170,17 @@ issue_1254_negate_iife_nested: {
};
})()()()()();
}
expect_exact: '!function(){return function(){console.log("test")}}()()()()();'
expect_exact: '(function(){return function(){console.log("test")}})()()()()();'
}
preserve_completion_value: {
options = {
negate_iife: true,
}
input: {
(function () { return true; })();
(function () { return true; })();
(function () { return true; })();
}
expect_exact: '!function(){return true}();!function(){return true}();(function(){return true})();'
}