@@ -1012,6 +1012,11 @@ merge(Compressor.prototype, {
|
|||||||
reset_def(tw, compressor, def);
|
reset_def(tw, compressor, def);
|
||||||
});
|
});
|
||||||
if (node.extends) node.extends.walk(tw);
|
if (node.extends) node.extends.walk(tw);
|
||||||
|
var props = node.properties.filter(function(prop) {
|
||||||
|
reset_flags(prop);
|
||||||
|
if (prop.key instanceof AST_Node) prop.key.walk(tw);
|
||||||
|
return prop.value;
|
||||||
|
});
|
||||||
if (node.name) {
|
if (node.name) {
|
||||||
var d = node.name.definition();
|
var d = node.name.definition();
|
||||||
var parent = tw.parent();
|
var parent = tw.parent();
|
||||||
@@ -1028,11 +1033,7 @@ merge(Compressor.prototype, {
|
|||||||
d.fixed = false;
|
d.fixed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node.properties.filter(function(prop) {
|
props.forEach(function(prop) {
|
||||||
reset_flags(prop);
|
|
||||||
if (prop.key instanceof AST_Node) prop.key.walk(tw);
|
|
||||||
return prop.value;
|
|
||||||
}).forEach(function(prop) {
|
|
||||||
if (!prop.static || prop instanceof AST_ClassField && prop.value.contains_this()) {
|
if (!prop.static || prop instanceof AST_ClassField && prop.value.contains_this()) {
|
||||||
push(tw);
|
push(tw);
|
||||||
prop.value.walk(tw);
|
prop.value.walk(tw);
|
||||||
@@ -7695,24 +7696,24 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
def(AST_Class, function(compressor, first_in_statement) {
|
function drop_class(self, compressor, first_in_statement) {
|
||||||
var exprs = [], values = [];
|
var exprs = [], values = [];
|
||||||
var props = this.properties;
|
var props = self.properties;
|
||||||
for (var i = 0; i < props.length; i++) {
|
for (var i = 0; i < props.length; i++) {
|
||||||
var prop = props[i];
|
var prop = props[i];
|
||||||
if (prop.key instanceof AST_Node) exprs.push(prop.key);
|
if (prop.key instanceof AST_Node) exprs.push(prop.key);
|
||||||
if (prop.static && prop.value
|
if (prop.static && prop.value
|
||||||
&& prop instanceof AST_ClassField
|
&& prop instanceof AST_ClassField
|
||||||
&& prop.value.has_side_effects(compressor)) {
|
&& prop.value.has_side_effects(compressor)) {
|
||||||
if (prop.value.contains_this()) return this;
|
if (prop.value.contains_this()) return self;
|
||||||
values.push(prop.value);
|
values.push(prop.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var base = this.extends;
|
var base = self.extends;
|
||||||
if (base) {
|
if (base) {
|
||||||
if (base instanceof AST_SymbolRef) base = base.fixed_value();
|
if (base instanceof AST_SymbolRef) base = base.fixed_value();
|
||||||
base = !safe_for_extends(base);
|
base = !safe_for_extends(base);
|
||||||
if (!base) exprs.unshift(this.extends);
|
if (!base) exprs.unshift(self.extends);
|
||||||
}
|
}
|
||||||
exprs = trim(exprs, compressor, first_in_statement);
|
exprs = trim(exprs, compressor, first_in_statement);
|
||||||
if (exprs) first_in_statement = false;
|
if (exprs) first_in_statement = false;
|
||||||
@@ -7722,26 +7723,32 @@ merge(Compressor.prototype, {
|
|||||||
exprs = [];
|
exprs = [];
|
||||||
}
|
}
|
||||||
if (base) {
|
if (base) {
|
||||||
var node = to_class_expr(this, true);
|
var node = to_class_expr(self, true);
|
||||||
node.properties = [];
|
node.properties = [];
|
||||||
if (exprs.length) node.properties.push(make_node(AST_ClassMethod, this, {
|
if (exprs.length) node.properties.push(make_node(AST_ClassMethod, self, {
|
||||||
key: make_sequence(this, exprs),
|
key: make_sequence(self, exprs),
|
||||||
value: make_node(AST_Function, this, {
|
value: make_node(AST_Function, self, {
|
||||||
argnames: [],
|
argnames: [],
|
||||||
body: [],
|
body: [],
|
||||||
}).init_vars(node),
|
}).init_vars(node),
|
||||||
}));
|
}));
|
||||||
exprs = [ node ];
|
exprs = [ node ];
|
||||||
}
|
}
|
||||||
if (values) exprs.push(make_node(AST_Call, this, {
|
if (values) exprs.push(make_node(AST_Call, self, {
|
||||||
expression: make_node(AST_Arrow, this, {
|
expression: make_node(AST_Arrow, self, {
|
||||||
argnames: [],
|
argnames: [],
|
||||||
body: [],
|
body: [],
|
||||||
value: make_sequence(this, values),
|
value: make_sequence(self, values),
|
||||||
}).init_vars(this.parent_scope),
|
}).init_vars(self.parent_scope),
|
||||||
args: [],
|
args: [],
|
||||||
}));
|
}));
|
||||||
return make_sequence(this, exprs);
|
return make_sequence(self, exprs);
|
||||||
|
}
|
||||||
|
def(AST_ClassExpression, function(compressor, first_in_statement) {
|
||||||
|
var self = this;
|
||||||
|
var name = self.name;
|
||||||
|
if (name && name.fixed_value() !== self && name.definition().references.length > 0) return self;
|
||||||
|
return drop_class(self, compressor, first_in_statement);
|
||||||
});
|
});
|
||||||
def(AST_Conditional, function(compressor) {
|
def(AST_Conditional, function(compressor) {
|
||||||
var consequent = this.consequent.drop_side_effect_free(compressor);
|
var consequent = this.consequent.drop_side_effect_free(compressor);
|
||||||
@@ -7782,6 +7789,9 @@ merge(Compressor.prototype, {
|
|||||||
return exprs.length == 0 ? null : make_sequence(this, exprs);
|
return exprs.length == 0 ? null : make_sequence(this, exprs);
|
||||||
});
|
});
|
||||||
def(AST_Constant, return_null);
|
def(AST_Constant, return_null);
|
||||||
|
def(AST_DefClass, function(compressor, first_in_statement) {
|
||||||
|
return drop_class(this, compressor, first_in_statement);
|
||||||
|
});
|
||||||
def(AST_Dot, function(compressor, first_in_statement) {
|
def(AST_Dot, function(compressor, first_in_statement) {
|
||||||
var expr = this.expression;
|
var expr = this.expression;
|
||||||
if (!this.optional && expr.may_throw_on_access(compressor)) return this;
|
if (!this.optional && expr.may_throw_on_access(compressor)) return this;
|
||||||
|
|||||||
@@ -1792,3 +1792,86 @@ issue_4996_2: {
|
|||||||
expect_stdout: "0"
|
expect_stdout: "0"
|
||||||
node_version: ">=12"
|
node_version: ">=12"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5015_1: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
var a;
|
||||||
|
try {
|
||||||
|
(class a {
|
||||||
|
[a]() {}
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
var a;
|
||||||
|
try {
|
||||||
|
(class a {
|
||||||
|
[a]() {}
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5015_2: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
try {
|
||||||
|
new class A {
|
||||||
|
[(A, 42)]() {}
|
||||||
|
}();
|
||||||
|
} catch (e) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
try {
|
||||||
|
new class A {
|
||||||
|
[(A, 42)]() {}
|
||||||
|
}();
|
||||||
|
} catch (e) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5015_3: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
(class A {
|
||||||
|
static f() {
|
||||||
|
return A;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user