@@ -117,7 +117,8 @@ namespace ts {
117
117
}
118
118
119
119
function addConvertToAsyncFunctionDiagnostics ( node : FunctionLikeDeclaration , checker : TypeChecker , diags : Push < DiagnosticWithLocation > ) : void {
120
- if ( ! visitedNestedConvertibleFunctions . has ( getKeyFromNode ( node ) ) && isConvertibleFunction ( node , checker ) ) {
120
+ // need to check function before checking map so that deeper levels of nested callbacks are checked
121
+ if ( isConvertibleFunction ( node , checker ) && ! visitedNestedConvertibleFunctions . has ( getKeyFromNode ( node ) ) ) {
121
122
diags . push ( createDiagnosticForNode (
122
123
! node . name && isVariableDeclaration ( node . parent ) && isIdentifier ( node . parent . name ) ? node . parent . name : node ,
123
124
Diagnostics . This_may_be_converted_to_an_async_function ) ) ;
@@ -128,7 +129,7 @@ namespace ts {
128
129
return ! isAsyncFunction ( node ) &&
129
130
node . body &&
130
131
isBlock ( node . body ) &&
131
- hasReturnStatementWithPromiseHandler ( node . body , checker ) &&
132
+ hasReturnStatementWithPromiseHandler ( node . body ) &&
132
133
returnsPromise ( node , checker ) ;
133
134
}
134
135
@@ -143,25 +144,25 @@ namespace ts {
143
144
return isBinaryExpression ( commonJsModuleIndicator ) ? commonJsModuleIndicator . left : commonJsModuleIndicator ;
144
145
}
145
146
146
- function hasReturnStatementWithPromiseHandler ( body : Block , checker : TypeChecker ) : boolean {
147
- return ! ! forEachReturnStatement ( body , stmt => isReturnStatementWithFixablePromiseHandler ( stmt , checker ) ) ;
147
+ function hasReturnStatementWithPromiseHandler ( body : Block ) : boolean {
148
+ return ! ! forEachReturnStatement ( body , isReturnStatementWithFixablePromiseHandler ) ;
148
149
}
149
150
150
- export function isReturnStatementWithFixablePromiseHandler ( node : Node , checker : TypeChecker ) : node is ReturnStatement {
151
- return isReturnStatement ( node ) && ! ! node . expression && isFixablePromiseHandler ( node . expression , checker ) ;
151
+ export function isReturnStatementWithFixablePromiseHandler ( node : Node ) : node is ReturnStatement {
152
+ return isReturnStatement ( node ) && ! ! node . expression && isFixablePromiseHandler ( node . expression ) ;
152
153
}
153
154
154
155
// Should be kept up to date with transformExpression in convertToAsyncFunction.ts
155
- export function isFixablePromiseHandler ( node : Node , checker : TypeChecker ) : boolean {
156
+ export function isFixablePromiseHandler ( node : Node ) : boolean {
156
157
// ensure outermost call exists and is a promise handler
157
- if ( ! isPromiseHandler ( node ) || ! node . arguments . every ( ( arg ) => isFixablePromiseArgument ( arg , checker ) ) ) {
158
+ if ( ! isPromiseHandler ( node ) || ! node . arguments . every ( isFixablePromiseArgument ) ) {
158
159
return false ;
159
160
}
160
161
161
162
// ensure all chained calls are valid
162
163
let currentNode = node . expression ;
163
164
while ( isPromiseHandler ( currentNode ) || isPropertyAccessExpression ( currentNode ) ) {
164
- if ( isCallExpression ( currentNode ) && ! currentNode . arguments . every ( arg => isFixablePromiseArgument ( arg , checker ) ) ) {
165
+ if ( isCallExpression ( currentNode ) && ! currentNode . arguments . every ( isFixablePromiseArgument ) ) {
165
166
return false ;
166
167
}
167
168
currentNode = currentNode . expression ;
@@ -174,14 +175,12 @@ namespace ts {
174
175
}
175
176
176
177
// should be kept up to date with getTransformationBody in convertToAsyncFunction.ts
177
- function isFixablePromiseArgument ( arg : Expression , checker : TypeChecker ) : boolean {
178
+ function isFixablePromiseArgument ( arg : Expression ) : boolean {
178
179
switch ( arg . kind ) {
179
180
case SyntaxKind . FunctionDeclaration :
180
181
case SyntaxKind . FunctionExpression :
181
182
case SyntaxKind . ArrowFunction :
182
- if ( isConvertibleFunction ( arg as FunctionLikeDeclaration , checker ) ) {
183
- visitedNestedConvertibleFunctions . set ( getKeyFromNode ( arg as FunctionLikeDeclaration ) , true ) ;
184
- }
183
+ visitedNestedConvertibleFunctions . set ( getKeyFromNode ( arg as FunctionLikeDeclaration ) , true ) ;
185
184
/* falls through */
186
185
case SyntaxKind . NullKeyword :
187
186
case SyntaxKind . Identifier : // identifier includes undefined
0 commit comments