diff --git a/lib/compress.js b/lib/compress.js index 202ce8f1d8b..d5057db5421 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6317,7 +6317,7 @@ Compressor.prototype.compress = function(node) { if (typeof this.key != "string") return false; var value = this.value; if (!value) return true; - return walk_scoped(value, scope); + return this.static ? value.is_constant_expression(scope) : walk_scoped(value, scope); }); def(AST_Constant, return_true); def(AST_Lambda, function(scope) { @@ -6326,6 +6326,9 @@ Compressor.prototype.compress = function(node) { def(AST_Object, function(scope) { return all_constant(this.properties, scope); }); + def(AST_ObjectIdentity, function(scope) { + return this.scope.resolve() === scope; + }); def(AST_ObjectProperty, function(scope) { return typeof this.key == "string" && this.value.is_constant_expression(scope); }); diff --git a/test/compress/classes.js b/test/compress/classes.js index 0e1e0217167..4335809bb63 100644 --- a/test/compress/classes.js +++ b/test/compress/classes.js @@ -3196,7 +3196,7 @@ issue_5082_2: { node_version: ">=12" } -issue_5082_2_static: { +issue_5082_2_strict: { options = { inline: true, passes: 2, @@ -4059,3 +4059,56 @@ issue_5874: { expect_stdout: "PASS" node_version: ">=12" } + +issue_5876_1: { + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + class A { + static p = this.q; + f() {} + } + if (A) + console.log("PASS"); + } + expect: { + class A { + static p = this.q; + f() {} + } + if (A) + console.log("PASS"); + } + expect_stdout: "PASS" + node_version: ">=12" +} + +issue_5876_2: { + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + class A { + static p = console.log("foo"); + } + if (A) + console.log("bar"); + } + expect: { + class A { + static p = console.log("foo"); + } + if (A) + console.log("bar"); + } + expect_stdout: [ + "foo", + "bar", + ] + node_version: ">=12" +} diff --git a/test/compress/functions.js b/test/compress/functions.js index 04c42031f30..2fa172fcf8f 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -8242,9 +8242,7 @@ issue_5328: { })(this); } expect: { - (function(arguments) { - console.log(Object.keys(arguments).join()); - })(this); + void console.log(Object.keys(this).join()); } expect_stdout: "" } diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 7b7cb67066d..36deccf0bcb 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -6882,9 +6882,7 @@ issue_3622: { } expect: { var c = "FAIL"; - var a; - a = this, - !void (a && (c = "PASS")), + !void (this && (c = "PASS")), console.log(c); } expect_stdout: "PASS"