diff --git a/lib/scope.js b/lib/scope.js index 0c861a7d..de35688e 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -61,7 +61,7 @@ SymbolDef.next_id = 1; SymbolDef.prototype = { unmangleable: function(options) { if (!options) options = {}; - + return (this.global && !options.toplevel) || this.export || this.undeclared @@ -71,6 +71,9 @@ SymbolDef.prototype = { || 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)) + || (options.reserved && options.reserved.indexOf(this.name) >= 0 && (this.orig[0] instanceof AST_SymbolClass || this.orig[0] instanceof AST_SymbolDefClass)); }, diff --git a/test/mocha/reserved-class.js b/test/mocha/reserved-class.js new file mode 100644 index 00000000..117dc21d --- /dev/null +++ b/test/mocha/reserved-class.js @@ -0,0 +1,27 @@ +var Uglify = require('../../'); +var assert = require("assert"); + +describe("mangle: reserved_class", function () { + var input_js = ` +(function() { + class Foo extends HTMLElement {} + Foo.reg; + class Hello extends HTMLElement {} + Hello.reg; +})(); +`; + var output_js = '!function(){class e extends HTMLElement{}e.reg;class Hello extends HTMLElement{}Hello.reg}();' + + it("Should test mangle with reserved_class.", function () { + var result = Uglify.minify(input_js, { + mangle: { + reserved: ['Hello'], + properties: false, + keep_classnames: false, + }, + }); + assert.strictEqual(result.code, output_js); + }); + + +});