From 3aabf88c0bcfeaeb398ae0d26c90c7c6267ec017 Mon Sep 17 00:00:00 2001 From: Jean-Louis GUENEGO Date: Sat, 23 Sep 2017 12:50:55 +0200 Subject: [PATCH] issue 2316 mangle and reserved --- lib/scope.js | 3 +++ test/compress/harmony.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/scope.js b/lib/scope.js index de35688e..48f4f3cb 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -549,6 +549,9 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){ var mangle_with_block_scope = (!options.ie8 && node instanceof AST_SymbolCatch) || node instanceof AST_SymbolBlockDeclaration; + if (options.reserved.indexOf(node.name) >= 0) { + mangle_with_block_scope = false; + } if (mangle_with_block_scope) { to_mangle.push(node.definition()); return; diff --git a/test/compress/harmony.js b/test/compress/harmony.js index 6078dd98..87cadebf 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -804,3 +804,21 @@ 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; + } + } + expect: { + function x(){class Foo{}Foo.bar;class o{}o.foo} + } +} \ No newline at end of file