});
if (can_inline && stat instanceof AST_Return) {
var value = stat.value;
- if (exp === fn && (!value || value.is_constant_expression())) {
+ if (exp === fn && (!value || value.is_constant_expression() && safe_from_await(value))) {
var args = self.args.concat(value || make_node(AST_Undefined, self));
return make_sequence(self, args).optimize(compressor);
}
}
return try_evaluate(compressor, self);
+ function safe_from_await(node) {
+ if (!is_async(scope || compressor.find_parent(AST_Scope))) return true;
+ var safe = true;
+ var tw = new TreeWalker(function(node) {
+ if (!safe) return true;
+ if (node instanceof AST_Scope) {
+ if (node === fn) return;
+ if (node instanceof AST_Arrow) {
+ for (var i = 0; safe && i < node.argnames.length; i++) node.argnames[i].walk(tw);
+ } else if (is_defun(node) && node.name.name == "await") {
+ safe = false;
+ }
+ return true;
+ }
+ if (node instanceof AST_Symbol && node.name == "await" && node !== fn.name) safe = false;
+ });
+ node.walk(tw);
+ return safe;
+ }
+
function return_value(stat) {
if (!stat) return make_node(AST_Undefined, self);
if (stat instanceof AST_Return) return stat.value || make_node(AST_Undefined, self);
}
if (node instanceof AST_Scope) return abort = true;
if (verify_await && node instanceof AST_Symbol && node.name == "await") {
- var scope = compressor.find_parent(AST_Scope);
- if (scope instanceof AST_AsyncDefun || scope instanceof AST_AsyncFunction) return abort = true;
+ if (is_async(compressor.find_parent(AST_Scope))) return abort = true;
verify_await = false;
}
if (node instanceof AST_SymbolRef) {
} while (!(scope instanceof AST_Scope));
insert = scope.body.indexOf(child) + 1;
if (!insert) return false;
- if (scope instanceof AST_AsyncDefun || scope instanceof AST_AsyncFunction) {
- var found = false;
- fn.walk(new TreeWalker(function(node) {
- if (found) return true;
- if (node instanceof AST_Scope && node !== fn) {
- if (is_defun(node) && node.name.name == "await") found = true;
- return true;
- }
- if (node instanceof AST_Symbol && node.name == "await" && node !== fn.name) return found = true;
- }));
- if (found) return false;
- }
+ if (!safe_from_await(fn)) return false;
var safe_to_inject = exp !== fn || fn.parent_scope.resolve() === scope;
if (scope instanceof AST_Toplevel) {
if (compressor.toplevel.vars) {