From e5604c9804a377a4687f32cf4267897697dd99c9 Mon Sep 17 00:00:00 2001 From: "zhengxie.lj" Date: Thu, 26 May 2016 18:52:50 +0800 Subject: [PATCH 1/2] bugfix #1095 --- lib/scope.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/scope.js b/lib/scope.js index 39bd9cbf..c7269347 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -86,6 +86,12 @@ SymbolDef.prototype = { var s = this.scope; if (!options.screw_ie8 && this.orig[0] instanceof AST_SymbolLambda) s = s.parent_scope; + + // https://github.com/mishoo/UglifyJS2/issues/1095 + // prevent mangle name conflict while using `let` or `const` + if (this.orig[0] instanceof AST_SymbolBlockDeclaration) + s = s.parent_scope; + this.mangled_name = s.next_mangled(options, this); if (this.global && cache) { cache.set(this.name, this.mangled_name); From 5b8417bd7db8639c3e71464021bab2c1e7b7b700 Mon Sep 17 00:00:00 2001 From: "zhengxie.lj" Date: Thu, 26 May 2016 23:52:18 +0800 Subject: [PATCH 2/2] check the start node for performance --- lib/scope.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/scope.js b/lib/scope.js index c7269347..5d0fb308 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -89,8 +89,12 @@ SymbolDef.prototype = { // https://github.com/mishoo/UglifyJS2/issues/1095 // prevent mangle name conflict while using `let` or `const` - if (this.orig[0] instanceof AST_SymbolBlockDeclaration) - s = s.parent_scope; + if (this.orig[0] instanceof AST_SymbolBlockDeclaration) { + var start = s.start; + if (start && start.type === 'keyword' && (start.value ==='default' || start.value === 'case')) { + s = s.parent_scope; + } + } this.mangled_name = s.next_mangled(options, this); if (this.global && cache) {