From 78d1bb92d4560b73099afddd3bd2a85641bf3002 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 5 Mar 2017 12:12:59 +0800 Subject: [PATCH] fix a corner case in #1530 (#1552) --- lib/compress.js | 10 ++++++---- test/compress/functions.js | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 35459006..7eead2c1 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2760,10 +2760,12 @@ merge(Compressor.prototype, { } } if (exp instanceof AST_Function) { - if (exp.body[0] instanceof AST_Return - && exp.body[0].value.is_constant()) { - var args = self.args.concat(exp.body[0].value); - return AST_Seq.from_array(args).transform(compressor); + if (exp.body[0] instanceof AST_Return) { + var value = exp.body[0].value; + if (!value || value.is_constant()) { + var args = self.args.concat(value || make_node(AST_Undefined, self)); + return AST_Seq.from_array(args).transform(compressor); + } } if (compressor.option("side_effects")) { if (!AST_Block.prototype.has_side_effects.call(exp, compressor)) { diff --git a/test/compress/functions.js b/test/compress/functions.js index 18505a18..a1a515a1 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -74,3 +74,20 @@ iifes_returning_constants_keep_fargs_false: { console.log((a(), b(), 6)); } } + +issue_485_crashing_1530: { + options = { + conditionals: true, + dead_code: true, + evaluate: true, + } + input: { + (function(a) { + if (true) return; + var b = 42; + })(this); + } + expect: { + this, void 0; + } +} -- 2.34.1