return node instanceof AST_Class || node instanceof AST_Lambda;
}
+ function safe_for_extends(node) {
+ return node instanceof AST_Class || node instanceof AST_Defun || node instanceof AST_Function;
+ }
+
function is_arguments(def) {
return def.name == "arguments" && def.scope.uses_arguments;
}
var base = this.extends;
if (base) {
if (base instanceof AST_SymbolRef) base = base.fixed_value();
- if (!is_lambda(base) || is_arrow(base)) return true;
+ if (!safe_for_extends(base)) return true;
}
return any(this.properties, compressor);
});
});
def(AST_Class, function(scope) {
var base = this.extends;
- if (base && (!is_lambda(base) || is_arrow(base))) return false;
+ if (base && !safe_for_extends(base)) return false;
return all_constant(this.properties, scope);
});
def(AST_ClassProperty, function(scope) {
var base = this.extends;
if (base) {
if (base instanceof AST_SymbolRef) base = base.fixed_value();
- base = !is_lambda(base) || is_arrow(base);
+ base = !safe_for_extends(base);
if (!base) exprs.unshift(this.extends);
}
exprs = trim(exprs, compressor, first_in_statement);
if (!base && !values) return null;
exprs = [];
}
- if (base) exprs.unshift(make_node(AST_ClassExpression, this, {
- extends: this.extends,
- properties: [],
- }));
if (values) {
var fn = make_node(AST_Arrow, this, {
argnames: [],
expression: fn,
}));
}
- return make_sequence(this, exprs);
+ exprs = exprs.length ? make_sequence(this, exprs) : null;
+ if (!base) return exprs;
+ var node = make_node(AST_ClassExpression, this, this);
+ node.name = null;
+ node.properties = [];
+ if (exprs) node.properties.push(make_node(AST_ClassMethod, this, {
+ key: exprs,
+ value: make_node(AST_Function, this, {
+ argnames: [],
+ body: [],
+ }).init_vars(node),
+ }));
+ return node;
});
def(AST_Conditional, function(compressor) {
var consequent = this.consequent.drop_side_effect_free(compressor);
single_use = false;
} else if (fixed.has_side_effects(compressor)) {
single_use = false;
+ } else if (compressor.option("ie8") && fixed instanceof AST_Class) {
+ single_use = false;
}
if (single_use) fixed.parent_scope = self.scope;
} else if (!fixed || !fixed.is_constant_expression() || fixed.drop_side_effect_free(compressor)) {
expect_stdout: "PASS"
node_version: ">=12"
}
+
+issue_4720: {
+ options = {
+ ie8: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ class A {
+ static p = function f() {};
+ }
+ console.log(typeof A.p, typeof f);
+ }
+ expect: {
+ class A {
+ static p = function f() {};
+ }
+ console.log(typeof A.p, typeof f);
+ }
+ expect_stdout: "function undefined"
+ node_version: ">=12"
+}
+
+issue_4721: {
+ options = {
+ side_effects: true,
+ }
+ input: {
+ "use strict";
+ var a = "foo";
+ try {
+ (class extends 42 {
+ [a = "bar"]() {}
+ })
+ } catch (e) {
+ console.log(a);
+ }
+ }
+ expect: {
+ "use strict";
+ var a = "foo";
+ try {
+ (class extends 42 {
+ [a = "bar"]() {}
+ });
+ } catch (e) {
+ console.log(a);
+ }
+ }
+ expect_stdout: true
+ node_version: ">=4"
+}
+
+issue_4722_1: {
+ options = {
+ side_effects: true,
+ }
+ input: {
+ "use strict";
+ try {
+ (class extends function*() {} {});
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect: {
+ "use strict";
+ try {
+ (class extends function*() {} {});
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect_stdout: "PASS"
+ node_version: ">=4"
+}
+
+issue_4722_2: {
+ options = {
+ side_effects: true,
+ }
+ input: {
+ "use strict";
+ try {
+ (class extends async function() {} {});
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect: {
+ "use strict";
+ try {
+ (class extends async function() {} {});
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect_stdout: "PASS"
+ node_version: ">=8"
+}
+
+issue_4722_3: {
+ options = {
+ side_effects: true,
+ }
+ input: {
+ "use strict";
+ try {
+ (class extends async function*() {} {});
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect: {
+ "use strict";
+ try {
+ (class extends async function*() {} {});
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect_stdout: "PASS"
+ node_version: ">=10"
+}