From e076abdbf24bc6acdfe34a11b607613016692e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Sat, 21 Nov 2015 13:59:18 +0000 Subject: [PATCH] Mangle class names correctly --- lib/scope.js | 9 +++++++-- test/compress/harmony.js | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/scope.js b/lib/scope.js index 4abebddb..3ae51dd4 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -66,7 +66,11 @@ SymbolDef.prototype = { || (!options.eval && (this.scope.uses_eval || this.scope.uses_with)) || (options.keep_fnames && (this.orig[0] instanceof AST_SymbolLambda - || this.orig[0] instanceof AST_SymbolDefun)); + || this.orig[0] instanceof AST_SymbolDefun)) + || this.orig[0] instanceof AST_SymbolMethod + || (options.keep_classnames + && (this.orig[0] instanceof AST_SymbolClass + || this.orig[0] instanceof AST_SymbolDefClass)); }, mangle: function(options) { var cache = options.cache && options.cache.props; @@ -379,7 +383,8 @@ AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options){ sort : false, toplevel : false, screw_ie8 : false, - keep_fnames : false + keep_fnames : false, + keep_classnames : false }); }); diff --git a/test/compress/harmony.js b/test/compress/harmony.js index c959b5d1..1d18301d 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -233,6 +233,24 @@ class_name_can_be_mangled: { } } +class_name_can_be_preserved: { + mangle = { + keep_classnames: true + } + input: { + function x() { + (class Baz { }); + class Foo {}; + } + } + expect: { + function x() { + (class Baz { }); + class Foo {}; + } + } +} + number_literals: { input: { 0b1001;