diff --git a/lib/compress/index.js b/lib/compress/index.js index 92dafe35f..cc9dbdc06 100644 --- a/lib/compress/index.js +++ b/lib/compress/index.js @@ -1338,6 +1338,7 @@ function tighten_body(statements, compressor) { || node instanceof AST_With || node instanceof AST_Yield || node instanceof AST_Export + || node instanceof AST_Class || parent instanceof AST_For && node !== parent.init || !replace_all && ( @@ -1507,21 +1508,7 @@ function tighten_body(statements, compressor) { function handle_custom_scan_order(node) { // Skip (non-executed) functions - if (node instanceof AST_Lambda) return node; - - // Skip the bits of classes that aren't executed immediately - if (node instanceof AST_Class) { - if (node.extends) node.extends = node.extends.transform(scanner); - for (const prop of node.properties) { - if (prop.computed_key()) { - prop.key = prop.key.transform(scanner); - } - if (prop.static && prop.value) { - prop.value = prop.value.transform(scanner); - } - } - return node; - } + if (node instanceof AST_Scope) return node; // Scan case expressions first in a switch statement if (node instanceof AST_Switch) { diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index d26624d28..05119626e 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -6007,147 +6007,20 @@ noinline_annotation: { } } -class_extends: { +ignore_class: { options = { - collapse_vars: true, - toplevel: true - } - input: { - var A; - A = class { - static which = 'A' - }; - class B extends A { static which = 'B' }; - console.log(B.which, A.which); - } - expect: { - var A; - class B extends (A = class { static which = 'A' }) { - static which = 'B' - }; - console.log(B.which, A.which); - } - expect_stdout: "B A" - node_version: ">=12" -} - -class_statics: { - options = { - collapse_vars: true, - toplevel: true - } - input: { - var A; - A = class { - static which = 'A' - }; - class B { - static which = 'B' - static A = A - }; - console.log(B.which, B.A.which, A.which); - } - expect: { - var A; - class B { - static which = 'B' - static A = (A = class { static which = 'A' }) - }; - console.log(B.which, B.A.which, A.which); - } - expect_stdout: "B A A" - node_version: ">=12" -} - -class_computed_prop_defs: { - options = { - collapse_vars: true, + defaults: true, toplevel: true } input: { - var A; - A = class { - static which = 'A' - }; - class B { - static which = 'B' - static [A.which] = A - }; - console.log(B.which, B.A.which, A.which); + global.leak = x => class dummy { get pass() { return x } } + global.module = {}; + (function () { + const SuperClass = leak("PASS") + class TheClass extends SuperClass {} + module.exports = TheClass + }()) + console.log(new module.exports().pass) } - expect: { - var A; - class B { - static which = 'B' - static [ - (A = class { - static which = 'A' - }).which - ] = A - }; - console.log(B.which, B.A.which, A.which); - } - expect_stdout: "B A A" - node_version: ">=12" -} - -class_computed_prop_defs_2: { - options = { - collapse_vars: true, - toplevel: true - } - input: { - var A; - A = class { - static which = 'A'; - }; - class B { - static which = 'B'; - [A.which] = A; - }; - console.log(B.which, new B().A.which, A.which); - } - expect: { - var A; - class B { - static which = 'B'; - [(A = class { - static which = 'A' - }).which] = A; - }; - console.log(B.which, new B().A.which, A.which); - } - expect_stdout: "B A A" - node_version: ">=12" -} - -class_regular_prop: { - options = { - collapse_vars: true, - toplevel: true - } - input: { - var A; - A = class { - static which = 'A' - }; - class B { - static which = 'B' - regular_prop = A - }; - console.log(B.which, new B().regular_prop.which, A.which); - } - expect: { - var A; - A = class { - static which = 'A' - }; - class B { - static which = 'B' - regular_prop = A - }; - console.log(B.which, new B().regular_prop.which, A.which); - } - expect_stdout: "B A A" - node_version: ">=12" + expect_stdout: "PASS" } diff --git a/test/compress/harmony.js b/test/compress/harmony.js index 2a78c7e25..ef3b83c0d 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -1776,8 +1776,8 @@ issue_3061: { } expect: { console.log(new class extends(function(base) { - return class extends Error {}; - }()){}() instanceof Error); + return class extends base {}; + }(Error)){}() instanceof Error); } expect_stdout: "true" }