From 12416000131558cd73d54613f7cd6437f4dc052e Mon Sep 17 00:00:00 2001 From: GUENEGO Jean-Louis Date: Sat, 23 Sep 2017 18:08:47 +0200 Subject: [PATCH] mangle: do not mangle reserved class (#2317) fixes #2316 --- lib/scope.js | 2 +- test/compress/harmony.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/scope.js b/lib/scope.js index 0c861a7d..deeb8092 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -546,7 +546,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){ var mangle_with_block_scope = (!options.ie8 && node instanceof AST_SymbolCatch) || node instanceof AST_SymbolBlockDeclaration; - if (mangle_with_block_scope) { + if (mangle_with_block_scope && options.reserved.indexOf(node.name) < 0) { to_mangle.push(node.definition()); return; } diff --git a/test/compress/harmony.js b/test/compress/harmony.js index 6078dd98..5891ee43 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -804,3 +804,39 @@ object_spread_of_sequence: { console.log({ ...o || o }); } } + +// issue 2316 +class_name_can_be_preserved_with_reserved: { + mangle = { + reserved: ['Foo'] + } + input: { + function x() { + class Foo {}; + Foo.bar; + class Bar {}; + Bar.foo; + } + + function y() { + var Foo = class Foo {}; + Foo.bar(); + var Bar = class Bar {}; + Bar.bar(); + } + } + expect: { + function x() { + class Foo {} + Foo.bar; + class a{} + a.foo + } + function y() { + var Foo = class Foo {}; + Foo.bar(); + var a = class a{}; + a.bar() + } + } +}