Skip to content

Commit

Permalink
fix corner case in inline (#5532)
Browse files Browse the repository at this point in the history
fixes #5531
  • Loading branch information
alexlamsl authored Jun 29, 2022
1 parent e1b03d0 commit 2426657
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -10784,7 +10784,9 @@ Compressor.prototype.compress = function(node) {
});
child = scope;
scope = compressor.parent(level++);
if (scope instanceof AST_DWLoop) {
if (scope instanceof AST_ClassField) {
if (!scope.static) return false;
} else if (scope instanceof AST_DWLoop) {
in_loop = [];
} else if (scope instanceof AST_For) {
if (scope.init === child) continue;
Expand Down
110 changes: 110 additions & 0 deletions test/compress/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3331,3 +3331,113 @@ issue_5512: {
expect_stdout: "PASS"
node_version: ">=16"
}

issue_5531_1: {
options = {
inline: true,
toplevel: true,
}
input: {
class A {
p = function() {
var a = function f() {
if (!a)
console.log("foo");
return 42;
}(a++);
}();
}
new A();
new A();
}
expect: {
class A {
p = function() {
var a = function f() {
if (!a)
console.log("foo");
return 42;
}(a++);
}();
}
new A();
new A();
}
expect_stdout: [
"foo",
"foo",
]
node_version: ">=12"
}

issue_5531_2: {
options = {
inline: true,
toplevel: true,
}
input: {
class A {
static p = function() {
var a = function f() {
if (!a)
console.log("foo");
return 42;
}(a++);
}();
}
new A();
new A();
}
expect: {
class A {
static p = (a = function f() {
if (!a)
console.log("foo");
return 42;
}(a++), void 0);
}
var a;
new A();
new A();
}
expect_stdout: "foo"
node_version: ">=12"
}

issue_5531_3: {
options = {
inline: true,
}
input: {
class A {
static {
(function() {
var a = function f() {
if (!a)
console.log("foo");
return 42;
}(a++);
})();
}
}
new A();
new A();
}
expect: {
class A {
static {
a = function f() {
if (!a)
console.log("foo");
return 42;
}(a++),
void 0;
var a;
}
}
new A();
new A();
}
expect_stdout: "foo"
node_version: ">=16"
}

0 comments on commit 2426657

Please sign in to comment.