From 766fafda8baefe6d150df27dfad7e99857c08557 Mon Sep 17 00:00:00 2001 From: Anthony Van de Gejuchte Date: Tue, 19 Jul 2016 18:03:08 +0200 Subject: [PATCH] Don't remove empty generators passed as parameter --- lib/compress.js | 1 + test/compress/yield.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/compress.js b/lib/compress.js index 21ec8e5c..21d8b50b 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2282,6 +2282,7 @@ merge(Compressor.prototype, { } if (compressor.option("side_effects")) { if (self.expression instanceof AST_Function + && !self.expression.is_generator && self.args.length == 0 && !AST_Block.prototype.has_side_effects.call(self.expression, compressor)) { return make_node(AST_Undefined, self).transform(compressor); diff --git a/test/compress/yield.js b/test/compress/yield.js index 9fe9f6c8..c29ce926 100644 --- a/test/compress/yield.js +++ b/test/compress/yield.js @@ -139,4 +139,30 @@ yield_as_identifier_outside_strict_mode: { var yield = "foo"; class yield {} } +} + +empty_generator_as_parameter_with_side_effects: { + options = { + side_effects: true + } + input: { + var GeneratorPrototype = Object.getPrototypeOf( + Object.getPrototypeOf(function*() {}()) + ); + evaluate(GeneratorPrototype); + } + expect_exact: "var GeneratorPrototype=Object.getPrototypeOf(Object.getPrototypeOf(function*(){}()));evaluate(GeneratorPrototype);" +} + +empty_generator_as_parameter_without_side_effects: { + options = { + side_effects: false + } + input: { + var GeneratorPrototype = Object.getPrototypeOf( + Object.getPrototypeOf(function*() {}()) + ); + evaluate(GeneratorPrototype); + } + expect_exact: "var GeneratorPrototype=Object.getPrototypeOf(Object.getPrototypeOf(function*(){}()));evaluate(GeneratorPrototype);" } \ No newline at end of file