Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

Commit 214d8ae

Browse files
committed
chore: simplify code to check only yield expressions
1 parent 9700900 commit 214d8ae

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

crates/rome_js_analyze/src/analyzers/nursery/use_yield.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rome_console::markup;
44
use rome_js_syntax::{
55
JsFunctionDeclaration, JsFunctionExpression, JsLanguage, JsMethodClassMember, JsSyntaxKind,
66
};
7-
use rome_rowan::{declare_node_union, AstNode, NodeOrToken, SyntaxNode, SyntaxToken};
7+
use rome_rowan::{declare_node_union, AstNode, SyntaxNode};
88

99
declare_rule! {
1010
/// Require generator functions to contain `yield`.
@@ -74,7 +74,7 @@ impl Rule for UseYield {
7474

7575
if start_token.is_some()
7676
&& !function_body_syntax.clone().into_list().is_empty()
77-
&& !has_yield_kw(NodeOrToken::from(function_body_syntax))?
77+
&& !has_yield_expression(function_body_syntax)?
7878
{
7979
return Some(());
8080
}
@@ -91,20 +91,18 @@ impl Rule for UseYield {
9191
}
9292
}
9393

94-
/// Traverses the syntax tree and verifies the presence of the yield keyword.
95-
fn has_yield_kw(
96-
node: NodeOrToken<SyntaxNode<JsLanguage>, SyntaxToken<JsLanguage>>,
97-
) -> Option<bool> {
98-
if node.kind() == JsSyntaxKind::YIELD_KW {
94+
/// Traverses the syntax tree and verifies the presence of n yield expression.
95+
fn has_yield_expression(node: SyntaxNode<JsLanguage>) -> Option<bool> {
96+
if node.kind() == JsSyntaxKind::JS_YIELD_EXPRESSION {
9997
return Some(true);
10098
}
10199

102-
if node.kind() == JsSyntaxKind::FUNCTION_KW || node.as_token().is_some() {
100+
if node.kind() == JsSyntaxKind::FUNCTION_KW {
103101
return Some(false);
104102
}
105103

106-
for child in node.as_node()?.children_with_tokens() {
107-
if !has_yield_kw(child)? {
104+
for child in node.children() {
105+
if !has_yield_expression(child)? {
108106
continue;
109107
}
110108

0 commit comments

Comments
 (0)