Skip to content

Commit 2426657

Browse files
authored
fix corner case in inline (#5532)
fixes #5531
1 parent e1b03d0 commit 2426657

File tree

2 files changed

+113
-1
lines changed

2 files changed

+113
-1
lines changed

lib/compress.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10784,7 +10784,9 @@ Compressor.prototype.compress = function(node) {
1078410784
});
1078510785
child = scope;
1078610786
scope = compressor.parent(level++);
10787-
if (scope instanceof AST_DWLoop) {
10787+
if (scope instanceof AST_ClassField) {
10788+
if (!scope.static) return false;
10789+
} else if (scope instanceof AST_DWLoop) {
1078810790
in_loop = [];
1078910791
} else if (scope instanceof AST_For) {
1079010792
if (scope.init === child) continue;

test/compress/classes.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3331,3 +3331,113 @@ issue_5512: {
33313331
expect_stdout: "PASS"
33323332
node_version: ">=16"
33333333
}
3334+
3335+
issue_5531_1: {
3336+
options = {
3337+
inline: true,
3338+
toplevel: true,
3339+
}
3340+
input: {
3341+
class A {
3342+
p = function() {
3343+
var a = function f() {
3344+
if (!a)
3345+
console.log("foo");
3346+
return 42;
3347+
}(a++);
3348+
}();
3349+
}
3350+
new A();
3351+
new A();
3352+
}
3353+
expect: {
3354+
class A {
3355+
p = function() {
3356+
var a = function f() {
3357+
if (!a)
3358+
console.log("foo");
3359+
return 42;
3360+
}(a++);
3361+
}();
3362+
}
3363+
new A();
3364+
new A();
3365+
}
3366+
expect_stdout: [
3367+
"foo",
3368+
"foo",
3369+
]
3370+
node_version: ">=12"
3371+
}
3372+
3373+
issue_5531_2: {
3374+
options = {
3375+
inline: true,
3376+
toplevel: true,
3377+
}
3378+
input: {
3379+
class A {
3380+
static p = function() {
3381+
var a = function f() {
3382+
if (!a)
3383+
console.log("foo");
3384+
return 42;
3385+
}(a++);
3386+
}();
3387+
}
3388+
new A();
3389+
new A();
3390+
}
3391+
expect: {
3392+
class A {
3393+
static p = (a = function f() {
3394+
if (!a)
3395+
console.log("foo");
3396+
return 42;
3397+
}(a++), void 0);
3398+
}
3399+
var a;
3400+
new A();
3401+
new A();
3402+
}
3403+
expect_stdout: "foo"
3404+
node_version: ">=12"
3405+
}
3406+
3407+
issue_5531_3: {
3408+
options = {
3409+
inline: true,
3410+
}
3411+
input: {
3412+
class A {
3413+
static {
3414+
(function() {
3415+
var a = function f() {
3416+
if (!a)
3417+
console.log("foo");
3418+
return 42;
3419+
}(a++);
3420+
})();
3421+
}
3422+
}
3423+
new A();
3424+
new A();
3425+
}
3426+
expect: {
3427+
class A {
3428+
static {
3429+
a = function f() {
3430+
if (!a)
3431+
console.log("foo");
3432+
return 42;
3433+
}(a++),
3434+
void 0;
3435+
var a;
3436+
}
3437+
}
3438+
new A();
3439+
new A();
3440+
}
3441+
expect_stdout: "foo"
3442+
node_version: ">=16"
3443+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy