From 79a5683fff9ef9fa679ba48c78c3d28d5b8ad9ad Mon Sep 17 00:00:00 2001 From: kzc Date: Thu, 29 Jun 2017 20:37:19 -0400 Subject: [PATCH] negate_iife: do not add `!` in front of arrow IIFE --- lib/compress.js | 10 +++++----- test/compress/async.js | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 3c6dc427..eef43396 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -561,8 +561,8 @@ merge(Compressor.prototype, { return orig.length == 1 && orig[0] instanceof AST_SymbolLambda; }); - function is_func_expr(node) { - return node instanceof AST_Arrow || node instanceof AST_Function; + function is_func_expr(node, traditional) { + return node instanceof AST_Function || !traditional && node instanceof AST_Arrow; } function is_lhs_read_only(lhs) { @@ -706,9 +706,9 @@ merge(Compressor.prototype, { return x; }; - function is_iife_call(node) { + function is_iife_call(node, traditional) { if (node instanceof AST_Call && !(node instanceof AST_New)) { - return is_func_expr(node.expression) || is_iife_call(node.expression); + return is_func_expr(node.expression, traditional) || is_iife_call(node.expression); } return false; } @@ -3452,7 +3452,7 @@ merge(Compressor.prototype, { } if (compressor.option("negate_iife") && compressor.parent() instanceof AST_SimpleStatement - && is_iife_call(self)) { + && is_iife_call(self, true)) { return self.negate(compressor, true); } var ev = self.evaluate(compressor); diff --git a/test/compress/async.js b/test/compress/async.js index 680ab94b..6025809e 100644 --- a/test/compress/async.js +++ b/test/compress/async.js @@ -261,3 +261,18 @@ async_arrow_iife: { } expect_exact: "(async()=>{await fetch({})})();" } + +async_arrow_iife_negate_iife: { + options = { + negate_iife: true, + } + input: { + (async () => { + await fetch(); + })(); + (() => { + plain(); + })(); + } + expect_exact: "(async()=>{await fetch()})();(()=>{plain()})();" +}