@@ -112,18 +112,27 @@ export default createRule({
112
112
}
113
113
114
114
/**
115
- * mark `scopeInfo.isAsyncYield` to `true` if its a generator
116
- * function and the delegate is `true`
115
+ * Mark `scopeInfo.isAsyncYield` to `true` if it
116
+ * 1) delegates async generator function
117
+ * or
118
+ * 2) yields thenable type
117
119
*/
118
- function markAsHasDelegateGen ( node : TSESTree . YieldExpression ) : void {
120
+ function visitYieldExpression ( node : TSESTree . YieldExpression ) : void {
119
121
if ( ! scopeInfo ?. isGen || ! node . argument ) {
120
122
return ;
121
123
}
122
124
123
125
if ( node . argument . type === AST_NODE_TYPES . Literal ) {
124
- // making this `false` as for literals we don't need to check the definition
126
+ // ignoring this as for literals we don't need to check the definition
125
127
// eg : async function* run() { yield* 1 }
126
- scopeInfo . isAsyncYield ||= false ;
128
+ return ;
129
+ }
130
+
131
+ if ( ! node . delegate ) {
132
+ if ( isThenableType ( services . esTreeNodeToTSNodeMap . get ( node . argument ) ) ) {
133
+ scopeInfo . isAsyncYield = true ;
134
+ }
135
+ return ;
127
136
}
128
137
129
138
const type = services . getTypeAtLocation ( node . argument ) ;
@@ -152,7 +161,7 @@ export default createRule({
152
161
AwaitExpression : markAsHasAwait ,
153
162
'VariableDeclaration[kind = "await using"]' : markAsHasAwait ,
154
163
'ForOfStatement[await = true]' : markAsHasAwait ,
155
- ' YieldExpression[delegate = true]' : markAsHasDelegateGen ,
164
+ YieldExpression : visitYieldExpression ,
156
165
157
166
// check body-less async arrow function.
158
167
// ignore `async () => await foo` because it's obviously correct
0 commit comments