diff --git a/lib/compress.js b/lib/compress.js index 05f83701..016216ba 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -10019,7 +10019,7 @@ Compressor.prototype.compress = function(node) { return make_sequence(self, convert_args(value)).optimize(compressor); } } - if (is_func) { + if (is_func && !fn.contains_this()) { var def, value, var_assigned = false; if (can_inline && !fn.uses_arguments @@ -10027,8 +10027,7 @@ Compressor.prototype.compress = function(node) { && !(fn.name && fn instanceof AST_LambdaExpression) && (exp === fn || !recursive_ref(compressor, def = exp.definition(), fn) && fn.is_constant_expression(find_scope(compressor))) - && (value = can_flatten_body(stat)) - && !fn.contains_this()) { + && (value = can_flatten_body(stat))) { var replacing = exp === fn || def.single_use && def.references.length - def.replaced == 1; if (can_substitute_directly()) { var args = self.args.slice(); diff --git a/test/compress/default-values.js b/test/compress/default-values.js index d263d5f6..b73d6416 100644 --- a/test/compress/default-values.js +++ b/test/compress/default-values.js @@ -2081,3 +2081,43 @@ issue_5256: { expect_stdout: "undefined" node_version: ">=8" } + +issue_5314_1: { + options = { + side_effects: true, + } + input: { + A = this; + new function() { + (function(a = console.log(this === A ? "PASS" : "FAIL")) {})(); + }(); + } + expect: { + A = this; + (function() { + (function(a = console.log(this === A ? "PASS" : "FAIL")) {})(); + })(); + } + expect_stdout: "PASS" + node_version: ">=6" +} + +issue_5314_2: { + options = { + side_effects: true, + } + input: { + A = this; + new function() { + ((a = console.log(this === A ? "FAIL" : "PASS")) => {})(); + }(); + } + expect: { + A = this; + new function() { + console.log(this === A ? "FAIL" : "PASS"); + }(); + } + expect_stdout: "PASS" + node_version: ">=6" +} diff --git a/test/compress/destructured.js b/test/compress/destructured.js index 4f382f2d..4b21ff29 100644 --- a/test/compress/destructured.js +++ b/test/compress/destructured.js @@ -3426,3 +3426,51 @@ issue_5288: { expect_stdout: "PASS" node_version: ">=6" } + +issue_5314_1: { + options = { + side_effects: true, + } + input: { + A = this; + new function() { + (function({ + [console.log(this === A ? "PASS" : "FAIL")]: a, + }) {})(42); + }(); + } + expect: { + A = this; + (function() { + (function({ + [console.log(this === A ? "PASS" : "FAIL")]: a, + }) {})(42); + })(); + } + expect_stdout: "PASS" + node_version: ">=6" +} + +issue_5314_2: { + options = { + side_effects: true, + } + input: { + A = this; + new function() { + (({ + [console.log(this === A ? "FAIL" : "PASS")]: a, + }) => {})(42); + }(); + } + expect: { + A = this; + new function() { + [ { + [console.log(this === A ? "FAIL" : "PASS")]: [].e, + } ] = [ 42 ]; + }(); + } + expect_stdout: "PASS" + node_version: ">=6" +}