};
function negate_iifes(statements, compressor) {
+ function is_iife_call(node) {
+ if (node instanceof AST_Call) {
+ return node.expression instanceof AST_Function || is_iife_call(node.expression);
+ }
+ return false;
+ }
+
statements.forEach(function(stat){
if (stat instanceof AST_SimpleStatement) {
stat.body = (function transform(thing) {
if (node instanceof AST_New) {
return node;
}
- if (node instanceof AST_Call && node.expression instanceof AST_Function) {
+ if (is_iife_call(node)) {
return make_node(AST_UnaryPrefix, node, {
operator: "!",
expression: node
});
PARENS([ AST_Unary, AST_Undefined ], function(output){
- if (this.expression instanceof AST_Call)
- return false;
var p = output.parent();
return p instanceof AST_PropAccess && p.expression === this
|| p instanceof AST_Call && p.expression === this;
}
expect_exact: '!function(){return function(){console.log("test")}}()();'
}
+
+issue_1254_negate_iife_nested: {
+ options = {
+ negate_iife: true,
+ }
+ input: {
+ (function() {
+ return function() {
+ console.log('test')
+ };
+ })()()()()();
+ }
+ expect_exact: '!function(){return function(){console.log("test")}}()()()()();'
+}
}
expect_exact: "x();x(-1);x(-1,-2);x(void 1,+2,-3,~4,!5,--a,++b,c--,d++,typeof e,delete f);(-1)();(-1)(-2);"
}
+
+new_with_unary_prefix: {
+ input: {
+ var bar = (+new Date()).toString(32);
+ }
+ expect_exact: 'var bar=(+new Date).toString(32);';
+}