drop unused extends properly (#5461)
This commit is contained in:
@@ -6788,7 +6788,6 @@ Compressor.prototype.compress = function(node) {
|
||||
}
|
||||
});
|
||||
// pass 3: we should drop declarations not in_use
|
||||
var unused_fn_names = [];
|
||||
var calls_to_drop_args = [];
|
||||
var fns_with_marked_args = [];
|
||||
var trimmer = new TreeTransformer(function(node) {
|
||||
@@ -6909,7 +6908,7 @@ Compressor.prototype.compress = function(node) {
|
||||
}
|
||||
}
|
||||
if (node instanceof AST_ClassExpression && node.name && drop_fn_name(node.name.definition())) {
|
||||
unused_fn_names.push(node);
|
||||
node.name = null;
|
||||
}
|
||||
if (node instanceof AST_Lambda) {
|
||||
if (drop_funcs && node !== self && node instanceof AST_LambdaDefinition) {
|
||||
@@ -6925,7 +6924,7 @@ Compressor.prototype.compress = function(node) {
|
||||
}
|
||||
}
|
||||
if (node instanceof AST_LambdaExpression && node.name && drop_fn_name(node.name.definition())) {
|
||||
unused_fn_names.push(node);
|
||||
node.name = null;
|
||||
}
|
||||
if (!(node instanceof AST_Accessor)) {
|
||||
var args, spread, trim = compressor.drop_fargs(node, parent);
|
||||
@@ -6966,6 +6965,7 @@ Compressor.prototype.compress = function(node) {
|
||||
}
|
||||
}
|
||||
var default_length = trim ? -1 : node.length();
|
||||
var trim_value = args && !node.uses_arguments && parent !== compressor.parent();
|
||||
for (var i = argnames.length; --i >= 0;) {
|
||||
var sym = argnames[i];
|
||||
if (sym instanceof AST_SymbolFunarg) {
|
||||
@@ -6987,7 +6987,7 @@ Compressor.prototype.compress = function(node) {
|
||||
} else {
|
||||
var trimmed = trim_destructured(sym, args[i], function(node) {
|
||||
return node.definition().id in in_use_ids ? node : null;
|
||||
}, !node.uses_arguments, sym);
|
||||
}, trim_value, sym);
|
||||
funarg = trimmed.name;
|
||||
if (trimmed.value) args[i] = trimmed.value;
|
||||
}
|
||||
@@ -7363,9 +7363,6 @@ Compressor.prototype.compress = function(node) {
|
||||
&& self.body[0].value == "use strict") {
|
||||
self.body.length = 0;
|
||||
}
|
||||
unused_fn_names.forEach(function(fn) {
|
||||
fn.name = null;
|
||||
});
|
||||
calls_to_drop_args.forEach(function(call) {
|
||||
drop_unused_call_args(call, compressor, fns_with_marked_args);
|
||||
});
|
||||
|
||||
@@ -341,7 +341,7 @@ drop_extends: {
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
keep_extends: {
|
||||
keep_extends_1: {
|
||||
options = {
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
@@ -366,6 +366,43 @@ keep_extends: {
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
keep_extends_2: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
(class extends Function {});
|
||||
console.log("PASS");
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
(class extends Function {});
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
keep_extends_3: {
|
||||
options = {
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
class A extends Function {}
|
||||
console.log("PASS");
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
(class extends Function {});
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
drop_name: {
|
||||
options = {
|
||||
unused: true,
|
||||
@@ -670,6 +707,58 @@ single_use_7: {
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
single_use_extends: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
class A extends class B {
|
||||
f() {
|
||||
return "PASS";
|
||||
}
|
||||
} {}
|
||||
console.log(new A().f());
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
console.log(new class extends class {
|
||||
f() {
|
||||
return "PASS";
|
||||
}
|
||||
} {}().f());
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
single_use_extends_non_strict: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
class A extends class B {
|
||||
f() {
|
||||
return "PASS";
|
||||
}
|
||||
} {}
|
||||
console.log(new A().f());
|
||||
}
|
||||
expect: {
|
||||
console.log(new class extends class {
|
||||
f() {
|
||||
return "PASS";
|
||||
}
|
||||
} {}().f());
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
collapse_non_strict: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
|
||||
@@ -3401,7 +3401,7 @@ issue_5222: {
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5288: {
|
||||
issue_5288_1: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
inline: true,
|
||||
@@ -3421,7 +3421,37 @@ issue_5288: {
|
||||
}() ]));
|
||||
}
|
||||
expect: {
|
||||
while (console ? console.log("PASS") : 0, void 0);
|
||||
while (function() {
|
||||
if (console)
|
||||
console.log("PASS");
|
||||
}(), void 0);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5288_2: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
inline: true,
|
||||
keep_fargs: false,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
varify: true,
|
||||
}
|
||||
input: {
|
||||
while (function([]) {}([ function f() {
|
||||
if (console)
|
||||
return console.log("PASS");
|
||||
else {
|
||||
let a = 0;
|
||||
}
|
||||
}() ]));
|
||||
}
|
||||
expect: {
|
||||
while (console && console.log("PASS"), void 0);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
|
||||
Reference in New Issue
Block a user