fix corner cases in keep_fnames (#5393)
This commit is contained in:
@@ -7121,6 +7121,7 @@ Compressor.prototype.compress = function(node) {
|
|||||||
if (def.orig.length > 1) return null;
|
if (def.orig.length > 1) return null;
|
||||||
if (def.assignments > 0) return false;
|
if (def.assignments > 0) return false;
|
||||||
if (def.name == name) return def;
|
if (def.name == name) return def;
|
||||||
|
if (compressor.option("keep_fnames")) return false;
|
||||||
var forbidden;
|
var forbidden;
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case "await":
|
case "await":
|
||||||
|
|||||||
@@ -96,15 +96,14 @@ function minify(files, options) {
|
|||||||
}, true);
|
}, true);
|
||||||
if (options.validate) AST_Node.enable_validation();
|
if (options.validate) AST_Node.enable_validation();
|
||||||
var timings = options.timings && { start: Date.now() };
|
var timings = options.timings && { start: Date.now() };
|
||||||
if (options.rename === undefined) options.rename = options.compress && options.mangle;
|
|
||||||
if (options.annotations !== undefined) set_shorthand("annotations", options, [ "compress", "output" ]);
|
if (options.annotations !== undefined) set_shorthand("annotations", options, [ "compress", "output" ]);
|
||||||
if (options.ie8) options.ie = options.ie || options.ie8;
|
if (options.ie8) options.ie = options.ie || options.ie8;
|
||||||
if (options.ie) set_shorthand("ie", options, [ "compress", "mangle", "output" ]);
|
if (options.ie) set_shorthand("ie", options, [ "compress", "mangle", "output", "rename" ]);
|
||||||
if (options.keep_fargs) set_shorthand("keep_fargs", options, [ "compress", "mangle" ]);
|
if (options.keep_fargs) set_shorthand("keep_fargs", options, [ "compress", "mangle", "rename" ]);
|
||||||
if (options.keep_fnames) set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
|
if (options.keep_fnames) set_shorthand("keep_fnames", options, [ "compress", "mangle", "rename" ]);
|
||||||
if (options.toplevel) set_shorthand("toplevel", options, [ "compress", "mangle" ]);
|
if (options.toplevel) set_shorthand("toplevel", options, [ "compress", "mangle", "rename" ]);
|
||||||
if (options.v8) set_shorthand("v8", options, [ "mangle", "output" ]);
|
if (options.v8) set_shorthand("v8", options, [ "mangle", "output", "rename" ]);
|
||||||
if (options.webkit) set_shorthand("webkit", options, [ "compress", "mangle", "output" ]);
|
if (options.webkit) set_shorthand("webkit", options, [ "compress", "mangle", "output", "rename" ]);
|
||||||
var quoted_props;
|
var quoted_props;
|
||||||
if (options.mangle) {
|
if (options.mangle) {
|
||||||
options.mangle = defaults(options.mangle, {
|
options.mangle = defaults(options.mangle, {
|
||||||
@@ -135,6 +134,7 @@ function minify(files, options) {
|
|||||||
init_cache(options.mangle.cache);
|
init_cache(options.mangle.cache);
|
||||||
init_cache(options.mangle.properties.cache);
|
init_cache(options.mangle.properties.cache);
|
||||||
}
|
}
|
||||||
|
if (options.rename === undefined) options.rename = options.compress && options.mangle;
|
||||||
if (options.sourceMap) {
|
if (options.sourceMap) {
|
||||||
options.sourceMap = defaults(options.sourceMap, {
|
options.sourceMap = defaults(options.sourceMap, {
|
||||||
content: null,
|
content: null,
|
||||||
@@ -190,8 +190,8 @@ function minify(files, options) {
|
|||||||
if (options.validate) toplevel.validate_ast();
|
if (options.validate) toplevel.validate_ast();
|
||||||
if (timings) timings.rename = Date.now();
|
if (timings) timings.rename = Date.now();
|
||||||
if (options.rename) {
|
if (options.rename) {
|
||||||
toplevel.figure_out_scope(options.mangle);
|
toplevel.figure_out_scope(options.rename);
|
||||||
toplevel.expand_names(options.mangle);
|
toplevel.expand_names(options.rename);
|
||||||
}
|
}
|
||||||
if (timings) timings.compress = Date.now();
|
if (timings) timings.compress = Date.now();
|
||||||
if (options.compress) {
|
if (options.compress) {
|
||||||
|
|||||||
@@ -183,13 +183,11 @@ function parse_test(file) {
|
|||||||
function reminify(orig_options, input_code, input_formatted, stdout) {
|
function reminify(orig_options, input_code, input_formatted, stdout) {
|
||||||
for (var i = 0; i < minify_options.length; i++) {
|
for (var i = 0; i < minify_options.length; i++) {
|
||||||
var options = JSON.parse(minify_options[i]);
|
var options = JSON.parse(minify_options[i]);
|
||||||
if (options.compress) [
|
[
|
||||||
"keep_fargs",
|
"keep_fargs",
|
||||||
"keep_fnames",
|
"keep_fnames",
|
||||||
].forEach(function(name) {
|
].forEach(function(name) {
|
||||||
if (name in orig_options) {
|
if (name in orig_options) options[name] = orig_options[name];
|
||||||
options.compress[name] = orig_options[name];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
var options_formatted = JSON.stringify(options, null, 4);
|
var options_formatted = JSON.stringify(options, null, 4);
|
||||||
options.validate = true;
|
options.validate = true;
|
||||||
|
|||||||
@@ -939,6 +939,8 @@ keep_fnames: {
|
|||||||
class Foo {}
|
class Foo {}
|
||||||
console.log(Foo.name, class Bar {}.name);
|
console.log(Foo.name, class Bar {}.name);
|
||||||
}
|
}
|
||||||
|
expect_stdout: "Foo Bar"
|
||||||
|
node_version: ">=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_805_1: {
|
issue_805_1: {
|
||||||
|
|||||||
@@ -3557,6 +3557,27 @@ functions_inner_var: {
|
|||||||
expect_stdout: "undefined undefined"
|
expect_stdout: "undefined undefined"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
functions_keep_fnames: {
|
||||||
|
options = {
|
||||||
|
functions: true,
|
||||||
|
keep_fnames: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var FAIL = function PASS() {};
|
||||||
|
FAIL.p = 42;
|
||||||
|
console.log(FAIL.name, FAIL.p);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var FAIL = function PASS() {};
|
||||||
|
FAIL.p = 42;
|
||||||
|
console.log(FAIL.name, FAIL.p);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS 42"
|
||||||
|
}
|
||||||
|
|
||||||
issue_2437: {
|
issue_2437: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user