return found;
});
+ function in_async_generator(scope) {
+ return scope instanceof AST_AsyncGeneratorDefun || scope instanceof AST_AsyncGeneratorFunction;
+ }
+
function find_scope(compressor) {
var level = 0, node;
while (node = compressor.parent(level++)) {
var stat = statements[i];
if (prev) {
if (stat instanceof AST_Exit) {
- stat.value = cons_seq(stat.value || make_node(AST_Undefined, stat)).transform(compressor);
+ if (stat.value || !in_async_generator(scope)) {
+ stat.value = cons_seq(stat.value || make_node(AST_Undefined, stat)).transform(compressor);
+ }
} else if (stat instanceof AST_For) {
if (!(stat.init instanceof AST_Definitions)) {
var abort = false;
});
OPT(AST_Return, function(self, compressor) {
- if (self.value && is_undefined(self.value, compressor)) {
+ if (compressor.option("side_effects")
+ && self.value
+ && is_undefined(self.value, compressor)
+ && !in_async_generator(compressor.find_parent(AST_Scope))) {
self.value = null;
}
return self;
expect_stdout: "undefined"
node_version: ">=4"
}
+
+issue_4641_1: {
+ options = {
+ sequences: true,
+ }
+ input: {
+ console.log(typeof async function*() {
+ try {
+ console.log("foo");
+ return;
+ } finally {
+ console.log("bar");
+ }
+ }().next().then);
+ }
+ expect: {
+ console.log(typeof async function*() {
+ try {
+ console.log("foo");
+ return;
+ } finally {
+ console.log("bar");
+ }
+ }().next().then);
+ }
+ expect_stdout: [
+ "foo",
+ "bar",
+ "function",
+ ]
+ node_version: ">=10"
+}
+
+issue_4641_2: {
+ options = {
+ side_effects: true,
+ }
+ input: {
+ console.log(typeof async function*() {
+ try {
+ return void "FAIL";
+ } finally {
+ console.log("PASS");
+ }
+ }().next().then);
+ }
+ expect: {
+ console.log(typeof async function*() {
+ try {
+ return void 0;
+ } finally {
+ console.log("PASS");
+ }
+ }().next().then);
+ }
+ expect_stdout: [
+ "function",
+ "PASS",
+ ]
+ node_version: ">=10"
+}