if (!base && !values) return null;
exprs = [];
}
- if (base) {
+ if (base || !compressor.has_directive("use strict")) {
var node = to_class_expr(self, true);
+ if (!base) node.extends = null;
node.properties = [];
- if (exprs.length) node.properties.push(make_node(AST_ClassMethod, self, {
- key: make_sequence(self, exprs),
- value: make_node(AST_Function, self, {
- argnames: [],
- body: [],
- }).init_vars(node),
- }));
- exprs = [ node ];
+ if (values) {
+ node.properties.push(make_node(AST_ClassField, self, {
+ static: true,
+ key: exprs.length ? make_sequence(self, exprs) : "c",
+ value: make_sequence(self, values),
+ }));
+ } else if (exprs.length) {
+ node.properties.push(make_node(AST_ClassMethod, self, {
+ key: make_sequence(self, exprs),
+ value: make_node(AST_Function, self, {
+ argnames: [],
+ body: [],
+ }).init_vars(node),
+ }));
+ }
+ return node;
}
if (values) exprs.push(make_node(AST_Call, self, {
expression: make_node(AST_Arrow, self, {
console.log(a);
}
expect: {
+ var a = "FAIL 1";
+ (class {
+ static c = a = "PASS";
+ });
+ console.log(a);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=12"
+}
+
+static_side_effects_strict: {
+ options = {
+ inline: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ "use strict";
+ var a = "FAIL 1";
+ class A {
+ static p = a = "PASS";
+ q = a = "FAIL 2";
+ }
+ console.log(a);
+ }
+ expect: {
+ "use strict";
var a = "FAIL 1";
a = "PASS";
console.log(a);
})();
}
expect: {
+ var await = "PASS";
+ (async function() {
+ (class {
+ static c = console.log(await);
+ });
+ })();
+ }
+ expect_stdout: true
+ node_version: ">=12 <16"
+}
+
+unused_await_strict: {
+ options = {
+ inline: true,
+ unused: true,
+ }
+ input: {
+ "use strict";
+ var await = "PASS";
+ (async function() {
+ class A {
+ static p = console.log(await);
+ }
+ })();
+ }
+ expect: {
+ "use strict";
var await = "PASS";
(async function() {
(() => console.log(await))();
}
}
expect: {
+ (class {
+ [console.log("PASS")]() {}
+ });
+ }
+ expect_stdout: "PASS"
+ node_version: ">=12"
+}
+
+issue_4705_strict: {
+ options = {
+ evaluate: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ "use strict";
+ var a = "PASS";
+ class A {
+ p = a = "FAIL";
+ [console.log(a)];
+ }
+ }
+ expect: {
+ "use strict";
console.log("PASS");
}
expect_stdout: "PASS"
expect: {
try {
(class extends 42 {
- [console.log("foo")]() {}
- }),
- (() => console.log("bar"))();
+ static [console.log("foo")] = console.log("bar");
+ });
+ } catch (e) {
+ console.log("baz");
+ }
+ }
+ expect_stdout: [
+ "foo",
+ "baz",
+ ]
+ node_version: ">=12"
+}
+
+issue_4756_strict: {
+ options = {
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ "use strict";
+ try {
+ class A extends 42 {
+ static [console.log("foo")] = console.log("bar");
+ }
+ } catch (e) {
+ console.log("baz");
+ }
+ }
+ expect: {
+ "use strict";
+ try {
+ (class extends 42 {
+ static [console.log("foo")] = console.log("bar");
+ });
} catch (e) {
console.log("baz");
}
input: {
"use strict";
try {
- class A extends { f(){} }.f {}
+ class A extends { f() {} }.f {}
} catch (e) {
console.log("PASS");
}
})(function g() {});
}
expect: {
+ (function g() {}),
+ void class {
+ static c = function() {
+ while (console.log(typeof g));
+ }();
+ };
+ }
+ expect_stdout: "undefined"
+ node_version: ">=12"
+}
+
+issue_4962_1_strict: {
+ options = {
+ ie: true,
+ inline: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ "use strict";
+ (function() {
+ function f() {
+ while (console.log(typeof g));
+ }
+ class A {
+ static p = f();
+ }
+ })(function g() {});
+ }
+ expect: {
+ "use strict";
(function g() {});
while (console.log(typeof g));
}
}, typeof g));
}
expect: {
+ console.log(function f() {}(function g() {
+ (class {
+ static c = f;
+ });
+ }));
+ }
+ expect_stdout: "undefined"
+ node_version: ">=12"
+}
+
+issue_4962_2_strict: {
+ options = {
+ ie: true,
+ inline: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ "use strict";
+ console.log(function f() {}(function g() {
+ function h() {
+ f;
+ }
+ class A {
+ static p = h();
+ }
+ }, typeof g));
+ }
+ expect: {
+ "use strict";
console.log(function f() {}(function g() {
f;
}));
})();
}
expect: {
+ (function() {
+ class A {
+ p = console.log("PASS");
+ q() {}
+ }
+ (class {
+ static c = new A();
+ });
+ })();
+ }
+ expect_stdout: "PASS"
+ node_version: ">=12"
+}
+
+issue_5082_1_strict: {
+ options = {
+ inline: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ "use strict";
+ (function() {
+ class A {
+ p = console.log("PASS");
+ q() {}
+ }
+ class B {
+ static P = new A();
+ }
+ })();
+ }
+ expect: {
+ "use strict";
(function() {
class A {
p = console.log("PASS");
})();
}
expect: {
+ (function() {
+ class A {
+ p = console.log("PASS");
+ q() {}
+ }
+ (class {
+ static c = new A();
+ });
+ })();
+ }
+ expect_stdout: "PASS"
+ node_version: ">=12"
+}
+
+issue_5082_2_static: {
+ options = {
+ inline: true,
+ passes: 2,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ "use strict";
+ (function() {
+ class A {
+ p = console.log("PASS");
+ q() {}
+ }
+ class B {
+ static P = new A();
+ }
+ })();
+ }
+ expect: {
+ "use strict";
void new class {
p = console.log("PASS");
q() {}
}
}
// ignore declaration order of global variables
- if (!ok && !toplevel) {
+ if (!ok && !toplevel && uglify_result.name != "SyntaxError" && original_result.name != "SyntaxError") {
ok = sandbox.same_stdout(run_code(sort_globals(original_code)), run_code(sort_globals(uglify_code)));
}
// ignore numerical imprecision caused by `unsafe_math`
// ignore difference in error message caused by Temporal Dead Zone
if (!ok && errored && uglify_result.name == "ReferenceError" && original_result.name == "ReferenceError") ok = true;
// ignore difference due to implicit strict-mode in `class`
- if (!ok && /\bclass\b/.test(original_code)) {
- var original_strict = run_code('"use strict";\n' + original_code, toplevel);
- var uglify_strict = run_code('"use strict";\n' + uglify_code, toplevel);
- if (typeof original_strict != "string") {
- ok = typeof uglify_strict != "string";
- } else {
- ok = sandbox.same_stdout(original_strict, uglify_strict);
- }
+ if (!ok && uglify_result.name == "SyntaxError" && /\bclass\b/.test(original_code)) {
+ ok = typeof run_code('"use strict";\n' + original_code, toplevel) != "string";
}
// ignore difference in error message caused by `import` symbol redeclaration
if (!ok && errored && /\bimport\b/.test(original_code)) {