From 303293e4aada63d7f1854df2c5b3da9036f0e1b3 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 31 May 2017 01:44:29 +0800 Subject: [PATCH] fix `side_effects` on `AST_Class` (#2031) fixes #2028 --- lib/compress.js | 2 +- test/compress/harmony.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index d1ba2986..b527557f 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -251,7 +251,7 @@ merge(Compressor.prototype, { }) }); } - if (node instanceof AST_Lambda && node !== self) { + if (node instanceof AST_Class || node instanceof AST_Lambda && node !== self) { return node; } if (node instanceof AST_Block) { diff --git a/test/compress/harmony.js b/test/compress/harmony.js index f92668ab..3b772976 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -583,3 +583,39 @@ class_extends_regex: { } expect_exact: "function f(){class rx1 extends(/rx/){}}" } + +issue_2028: { + options = { + side_effects: true, + } + input: { + var a = {}; + (function(x) { + x.X = function() { + return X; + }; + class X { + static hello() { + console.log("hello"); + } + } + }(a)); + a.X().hello(); + } + expect: { + var a = {}; + (function(x) { + x.X = function() { + return X; + }; + class X { + static hello() { + console.log("hello"); + } + } + }(a)); + a.X().hello(); + } + expect_stdout: "hello" + node_version: ">=6" +}