mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix: no return await error (#539)
This commit is contained in:
parent
2d984f0401
commit
357b28eb96
1 changed files with 8 additions and 4 deletions
|
|
@ -54,8 +54,10 @@ fn is_in_tail_call_position<'a>(node: &AstNode<'a>, ctx: &LintContext<'a>) -> bo
|
|||
if let Some(parent) = ctx.nodes().parent_node(node.id()) {
|
||||
let parent_kind = parent.kind();
|
||||
match parent_kind {
|
||||
AstKind::ArrowExpression(_) => {
|
||||
return true;
|
||||
AstKind::ArrowExpression(arrow_expr) => {
|
||||
// async () => { await b(); })
|
||||
// `epxression` property is false
|
||||
return arrow_expr.expression;
|
||||
}
|
||||
AstKind::ReturnStatement(_) => {
|
||||
return !has_error_handler(node, ctx);
|
||||
|
|
@ -92,8 +94,9 @@ fn is_in_tail_call_position<'a>(node: &AstNode<'a>, ctx: &LintContext<'a>) -> bo
|
|||
},
|
||||
// last statement in `func_body`
|
||||
AstKind::FunctionBody(func_body) => {
|
||||
if let Some(func_body_stat_last) = func_body.statements.last() {
|
||||
return func_body_stat_last.span() == node.kind().span();
|
||||
if let Some(func_body_stat_last) = func_body.statements.last()
|
||||
&& func_body_stat_last.span() == node.kind().span() {
|
||||
return is_in_tail_call_position(parent, ctx);
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
|
|
@ -144,6 +147,7 @@ fn test() {
|
|||
use crate::tester::Tester;
|
||||
|
||||
let pass = vec![
|
||||
("\nasync () => { await b(); }", None),
|
||||
("\nasync function foo() {\n\tawait bar(); return;\n}\n", None),
|
||||
("\nasync function foo() {\n\tconst x = await bar(); return x;\n}\n", None),
|
||||
("\nasync () => { return bar(); }\n", None),
|
||||
|
|
|
|||
Loading…
Reference in a new issue