diff --git a/lib/compress.js b/lib/compress.js index 21d8b50b..22d3f873 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -847,6 +847,13 @@ merge(Compressor.prototype, { }; 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) { @@ -854,7 +861,7 @@ merge(Compressor.prototype, { 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 diff --git a/lib/output.js b/lib/output.js index 3d932bd4..c0d3632a 100644 --- a/lib/output.js +++ b/lib/output.js @@ -575,8 +575,6 @@ function OutputStream(options) { }); 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 diff --git a/package.json b/package.json index 2af9005f..09346e8c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "homepage": "http://lisperator.net/uglifyjs", "author": "Mihai Bazon (http://lisperator.net/)", "license": "BSD-2-Clause", - "version": "2.7.1", + "version": "2.7.2", "engines": { "node": ">=0.8.0" }, diff --git a/test/compress/negate-iife.js b/test/compress/negate-iife.js index aa95d958..0c111604 100644 --- a/test/compress/negate-iife.js +++ b/test/compress/negate-iife.js @@ -158,3 +158,17 @@ issue_1254_negate_iife_true: { } 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")}}()()()()();' +} diff --git a/test/compress/new.js b/test/compress/new.js index bdf22b0c..83da88e6 100644 --- a/test/compress/new.js +++ b/test/compress/new.js @@ -75,3 +75,10 @@ call_with_unary_arguments: { } 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);'; +}