@@ -3964,12 +3964,19 @@ Compressor.prototype.compress = function(node) {
|
||||
for (var index = statements.length; --index >= 0;) {
|
||||
var stat = statements[index];
|
||||
if (!(stat instanceof AST_SimpleStatement)) break;
|
||||
var node = stat.body;
|
||||
var node = stat.body.tail_node();
|
||||
if (!(node instanceof AST_Await)) break;
|
||||
var exp = node.expression;
|
||||
if (!needs_enqueuing(compressor, exp)) break;
|
||||
changed = true;
|
||||
exp = exp.drop_side_effect_free(compressor, true);
|
||||
if (stat.body instanceof AST_Sequence) {
|
||||
var expressions = stat.body.expressions.slice();
|
||||
expressions.pop();
|
||||
if (exp) expressions.push(exp);
|
||||
stat.body = make_sequence(stat.body, expressions);
|
||||
break;
|
||||
}
|
||||
if (exp) {
|
||||
stat.body = exp;
|
||||
break;
|
||||
@@ -11752,7 +11759,16 @@ Compressor.prototype.compress = function(node) {
|
||||
return !lazy_op[node.operator]
|
||||
|| needs_enqueuing(compressor, node.left) && needs_enqueuing(compressor, node.right);
|
||||
}
|
||||
if (node instanceof AST_Call) return is_async(node.expression);
|
||||
if (node instanceof AST_Call) {
|
||||
if (!is_async(node.expression)) return false;
|
||||
var has_await = false;
|
||||
walk_body(node.expression, new TreeWalker(function(expr) {
|
||||
if (has_await) return true;
|
||||
if (expr instanceof AST_Await) return has_await = true;
|
||||
if (expr !== node && expr instanceof AST_Scope) return true;
|
||||
}));
|
||||
return !has_await;
|
||||
}
|
||||
if (node instanceof AST_Conditional) {
|
||||
return needs_enqueuing(compressor, node.consequent) && needs_enqueuing(compressor, node.alternative);
|
||||
}
|
||||
|
||||
@@ -3642,3 +3642,66 @@ issue_5692_2: {
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5791: {
|
||||
options = {
|
||||
awaits: true,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(async function() {
|
||||
async function f() {
|
||||
try {
|
||||
await {
|
||||
then(resolve) {
|
||||
setImmediate(() => {
|
||||
console.log("foo");
|
||||
resolve();
|
||||
});
|
||||
},
|
||||
};
|
||||
} catch (e) {
|
||||
console.log("FAIL", e);
|
||||
}
|
||||
}
|
||||
async function g() {
|
||||
try {
|
||||
await f();
|
||||
} catch (e) {}
|
||||
}
|
||||
await g();
|
||||
console.log("bar");
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(async function() {
|
||||
await async function() {
|
||||
try {
|
||||
await async function() {
|
||||
try {
|
||||
await {
|
||||
then(resolve) {
|
||||
setImmediate(() => {
|
||||
console.log("foo");
|
||||
resolve();
|
||||
});
|
||||
},
|
||||
};
|
||||
} catch (e) {
|
||||
console.log("FAIL", e);
|
||||
}
|
||||
}();
|
||||
} catch (e) {}
|
||||
}();
|
||||
console.log("bar");
|
||||
})();
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user