Skip to content

Commit

Permalink
fix corner case in inline (#5957)
Browse files Browse the repository at this point in the history
fixes #5956
  • Loading branch information
alexlamsl authored Oct 30, 2024
1 parent c650e72 commit 0acdd83
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -14330,18 +14330,22 @@ Compressor.prototype.compress = function(node) {
if (node instanceof AST_Return) return abort = true;
if (node instanceof AST_Scope) return true;
});
stat.walk(new TreeWalker(function(node) {
var tw = new TreeWalker(function(node) {
if (abort) return true;
if (node instanceof AST_Try) {
if (!node.bfinally) return;
if (all(node.body, function(stat) {
stat.walk(find_return);
return !abort;
}) && node.bcatch) node.bcatch.walk(find_return);
})) {
if (node.bcatch) node.bcatch.walk(find_return);
node.bfinally.walk(tw);
}
return true;
}
if (node instanceof AST_Scope) return true;
}));
});
stat.walk(tw);
return !abort;
};
}
Expand Down
85 changes: 85 additions & 0 deletions test/compress/awaits.js
Original file line number Diff line number Diff line change
Expand Up @@ -3729,3 +3729,88 @@ issue_5791: {
]
node_version: ">=8"
}

issue_5842: {
options = {
awaits: true,
inline: true,
}
input: {
var a = "FAIL";
(async function() {
await function() {
try {
try {
return console;
} finally {
a = "PASS";
}
} catch (e) {}
FAIL;
}();
})();
console.log(a);
}
expect: {
var a = "FAIL";
(async function() {
await function() {
try {
try {
return console;
} finally {
a = "PASS";
}
} catch (e) {}
FAIL;
}();
})();
console.log(a);
}
expect_stdout: "PASS"
node_version: ">=8"
}

issue_5956: {
options = {
awaits: true,
inline: true,
}
input: {
(async function() {
await function() {
try {
FAIL;
} finally {
try {
return 42;
} finally {
console.log("foo");
}
}
}();
})();
console.log("bar");
}
expect: {
(async function() {
await function() {
try {
FAIL;
} finally {
try {
return 42;
} finally {
console.log("foo");
}
}
}();
})();
console.log("bar");
}
expect_stdout: [
"foo",
"bar",
]
node_version: ">=8"
}
43 changes: 43 additions & 0 deletions test/compress/yields.js
Original file line number Diff line number Diff line change
Expand Up @@ -2302,3 +2302,46 @@ issue_5842: {
expect_stdout: "PASS"
node_version: ">=10"
}

issue_5956: {
options = {
inline: true,
}
input: {
(async function*() {
(function() {
try {
FAIL;
} finally {
try {
return console;
} finally {
console.log("foo");
}
}
})();
})().next();
console.log("bar");
}
expect: {
(async function*() {
(function() {
try {
FAIL;
} finally {
try {
return console;
} finally {
console.log("foo");
}
}
})();
})().next();
console.log("bar");
}
expect_stdout: [
"foo",
"bar",
]
node_version: ">=10"
}

0 comments on commit 0acdd83

Please sign in to comment.