This commit is contained in:
Richard van Velzen 2017-02-13 08:56:49 +00:00 committed by GitHub
commit c39e64a577
2 changed files with 25 additions and 3 deletions

View File

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

View File

@ -6,7 +6,7 @@ negate_iife_1: {
(function(){ stuff() })(); (function(){ stuff() })();
} }
expect: { 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: { 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})();'
} }