separate keep_classnames & keep_fnames (#2510)

fixes #2418
This commit is contained in:
Alex Lam S.L
2017-11-25 16:31:52 +08:00
committed by GitHub
parent bbf38dc9c0
commit f1e3ef5262
5 changed files with 113 additions and 2 deletions

View File

@@ -69,6 +69,7 @@ function Compressor(options, false_by_default) {
if_return : !false_by_default,
inline : !false_by_default,
join_vars : !false_by_default,
keep_classnames: false,
keep_fargs : true,
keep_fnames : false,
keep_infinity : false,
@@ -2610,8 +2611,9 @@ merge(Compressor.prototype, {
// pass 3: we should drop declarations not in_use
var tt = new TreeTransformer(
function before(node, descend, in_list) {
if (!compressor.option("keep_fnames")
&& node.name && (node instanceof AST_Function || node instanceof AST_ClassExpression)) {
if (node.name
&& (!compressor.option("keep_classnames") && node instanceof AST_ClassExpression
|| !compressor.option("keep_fnames") && node instanceof AST_Function)) {
var def = node.name.definition();
// any declarations with same name will overshadow
// name of this anonymous function and can therefore

View File

@@ -51,6 +51,7 @@ function minify(files, options) {
compress: {},
ecma: undefined,
ie8: false,
keep_classnames: undefined,
keep_fnames: false,
mangle: {},
nameCache: null,
@@ -65,8 +66,12 @@ function minify(files, options) {
var timings = options.timings && {
start: Date.now()
};
if (options.keep_classnames === undefined) {
options.keep_classnames = options.keep_fnames;
}
set_shorthand("ecma", options, [ "parse", "compress", "output" ]);
set_shorthand("ie8", options, [ "compress", "mangle", "output" ]);
set_shorthand("keep_classnames", options, [ "compress", "mangle" ]);
set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
set_shorthand("toplevel", options, [ "compress", "mangle" ]);
set_shorthand("warnings", options, [ "compress" ]);