mangle: do not mangle reserved class

This commit is contained in:
Jean-Louis GUENEGO 2017-09-17 18:42:37 +02:00
parent c46b9f361a
commit daf099178d
2 changed files with 31 additions and 1 deletions

View File

@ -71,6 +71,9 @@ SymbolDef.prototype = {
|| this.orig[0] instanceof AST_SymbolDefun)) || this.orig[0] instanceof AST_SymbolDefun))
|| this.orig[0] instanceof AST_SymbolMethod || this.orig[0] instanceof AST_SymbolMethod
|| (options.keep_classnames || (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_SymbolClass
|| this.orig[0] instanceof AST_SymbolDefClass)); || this.orig[0] instanceof AST_SymbolDefClass));
}, },

View File

@ -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);
});
});