diff --git a/lib/compress.js b/lib/compress.js index 88d66c51..79a507fe 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4641,8 +4641,13 @@ merge(Compressor.prototype, { if (compressor.option("unsafe") && self.expression instanceof AST_Object) { var values = self.expression.properties; for (var i = values.length; --i >= 0;) { - if (values[i].key === prop) { + var key = values[i].key; + if ((key instanceof AST_SymbolMethod ? key.name : key) === prop) { var value = values[i].value; + if (key instanceof AST_SymbolMethod) { + if (values[i].is_generator) break; + value = make_node(AST_Function, value, value); + } if (value instanceof AST_Function ? !value.contains_this() : !value.has_side_effects(compressor)) { var obj = self.expression.clone(); obj.properties = obj.properties.slice(); diff --git a/test/compress/properties.js b/test/compress/properties.js index 796bf48f..13c34d58 100644 --- a/test/compress/properties.js +++ b/test/compress/properties.js @@ -772,3 +772,97 @@ issue_2208_5: { } expect_stdout: "42" } + +issue_2208_6: { + options = { + inline: true, + side_effects: true, + unsafe: true, + } + input: { + console.log({ + p: () => 42 + }.p()); + } + expect: { + console.log(42); + } + expect_stdout: "42" + node_version: ">=4" +} + +issue_2208_7: { + options = { + inline: true, + side_effects: true, + unsafe: true, + } + input: { + console.log({ + p() { + return 42; + } + }.p()); + } + expect: { + console.log(42); + } + expect_stdout: "42" + node_version: ">=4" +} + +issue_2208_8: { + options = { + inline: true, + side_effects: true, + unsafe: true, + } + input: { + console.log({ + *p() { + return x(); + } + }.p()); + console.log({ + async p() { + return await x(); + } + }.p()); + } + expect: { + console.log({ + *p() { + return x(); + } + }.p()); + console.log(async function() { + return await x(); + }()); + } +} + +issue_2208_9: { + options = { + inline: true, + side_effects: true, + unsafe: true, + } + input: { + a = 42; + console.log({ + p: () => { + return function() { + return this.a; + }(); + } + }.p()); + } + expect: { + a = 42; + console.log(function() { + return this.a; + }()); + } + expect_stdout: "42" + node_version: ">=4" +}