refactor(transformer/async-generator-functions): remove dead code for handle await expression (#7131)

I thought wrong previously, this should be transformed in the async-to-generator rather than async-generator-functions
This commit is contained in:
Dunqing 2024-11-06 03:27:12 +00:00
parent b6a575009a
commit 5ce83bddc6

View file

@ -222,35 +222,10 @@ impl<'a, 'ctx> AsyncGeneratorFunctions<'a, 'ctx> {
return None;
}
let mut is_function = false;
let mut function_in_params = false;
for ancestor in ctx.ancestors() {
match ancestor {
Ancestor::FunctionBody(_) if !is_function => {
is_function = true;
}
// x = async function() { await 1 }
Ancestor::AssignmentPatternRight(_) | Ancestor::BindingPatternKind(_) => {
continue;
}
Ancestor::FormalParameterPattern(_) => {
function_in_params = true;
break;
}
_ => {
if is_function {
break;
}
}
}
}
let mut argument = ctx.ast.move_expression(&mut expr.argument);
// When a async function is used as parameter, we don't need to wrap its await expression with awaitAsyncGenerator helper.
// `function example(a = async function b() { await 1 }) {}`
if !function_in_params {
let arguments = ctx.ast.vec1(Argument::from(argument));
argument = self.ctx.helper_call_expr(Helper::AwaitAsyncGenerator, arguments, ctx);
}
let arguments = ctx.ast.vec1(Argument::from(argument));
argument = self.ctx.helper_call_expr(Helper::AwaitAsyncGenerator, arguments, ctx);
Some(ctx.ast.expression_yield(SPAN, false, Some(argument)))
}
}