Skip to content

Commit

Permalink
fix(linter): AllowFunction doesn't support generator (#2277)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing authored Feb 2, 2024
1 parent 3cb8577 commit 37a2676
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions crates/oxc_linter/src/rules/eslint/require_yield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,13 @@ impl Rule for RequireYield {
return;
}

let span = match kind {
AstKind::Function(func)
if func.generator
&& func.body.as_ref().is_some_and(|body| !body.statements.is_empty()) =>
if let AstKind::Function(func) = kind {
if func.generator && func.body.as_ref().is_some_and(|body| !body.statements.is_empty())
{
func.id.as_ref().map_or_else(|| kind.span(), |ident| ident.span)
let span = func.id.as_ref().map_or_else(|| kind.span(), |ident| ident.span);
ctx.diagnostic(RequireYieldDiagnostic(span));
}
AstKind::ArrowExpression(arrow) if !arrow.body.statements.is_empty() => arrow.span,
_ => return,
};

ctx.diagnostic(RequireYieldDiagnostic(span));
}
}
}

Expand All @@ -72,6 +67,7 @@ fn test() {
("var obj = { *foo() { } };", None),
("class A { *foo() { yield 0; } };", None),
("class A { *foo() { } };", None),
("() => {}", None),
];

let fail = vec![
Expand Down

0 comments on commit 37a2676

Please sign in to comment.