@@ -10,6 +10,7 @@ interface QueryMetadata {
10
10
interface NodeMetadata {
11
11
callName : string
12
12
callType : string
13
+ isAsync ?: boolean
13
14
start : number
14
15
end : number
15
16
args : ( Expression | SpreadElement | JSXNamespacedName | ArgumentPlaceholder ) [ ]
@@ -38,11 +39,17 @@ export function collectNodes(statements: Statement[], calls: Record<string, stri
38
39
const nodes : NodeMetadata [ ] = [ ]
39
40
40
41
statements . forEach ( ( x ) => {
42
+ if ( x . type === 'FunctionDeclaration' && x . body . type === 'BlockStatement' )
43
+ nodes . push ( ...collectNodes ( x . body . body , calls ) )
44
+
41
45
if ( x . type === 'VariableDeclaration' ) {
42
46
x . declarations . forEach ( ( y ) => {
43
47
const z = y . init
44
48
45
- if ( z && z . type === 'CallExpression' && isOneOfCall ( z , Object . values ( calls ) ) ) {
49
+ if ( z && z . type === 'ArrowFunctionExpression' && z . body . type === 'BlockStatement' ) {
50
+ nodes . push ( ...collectNodes ( z . body . body , calls ) )
51
+ }
52
+ else if ( z && z . type === 'CallExpression' && isOneOfCall ( z , Object . values ( calls ) ) ) {
46
53
const { start, end, arguments : args } = z
47
54
48
55
nodes . push ( {
@@ -53,6 +60,21 @@ export functio
8000
n collectNodes(statements: Statement[], calls: Record<string, stri
53
60
args,
54
61
} )
55
62
}
63
+ else if ( z && z . type === 'AwaitExpression' && isOneOfCall ( z . argument , Object . values ( calls ) ) ) {
64
+ if ( z . argument . type === 'CallExpression' ) {
65
+ const { start, end, argument : { arguments : args } } = z
66
+ const cName = callName ( z . argument )
67
+
68
+ nodes . push ( {
69
+ callName : cName ,
70
+ isAsync : true ,
71
+ callType : Object . entries ( calls ) . find ( ( [ _ , value ] ) => value === cName ) ! [ 0 ] ,
72
+ start : start ! ,
73
+ end : end ! ,
74
+ args,
75
+ } )
76
+ }
77
+ }
56
78
} )
57
79
}
58
80
else if ( x . type === 'ExpressionStatement' && x . expression . type === 'CallExpression' && isOneOfCall ( x . expression , Object . values ( calls ) ) ) {
@@ -66,6 +88,21 @@ export function collectNodes(statements: Statement[], calls: Record<string, stri
66
88
args,
67
89
} )
68
90
}
91
+ else if ( x . type === 'ExpressionStatement' && x . expression . type === 'AwaitExpression' && isOneOfCall ( x . expression . argument , Object . values ( calls ) ) ) {
92
+ if ( x . expression . argument . type === 'CallExpression' ) {
93
+ const { start, end, expression : { argument : { arguments : args } } } = x
94
+ const cName = callName ( x . expression . argument )
95
+
96
+ nodes . push ( {
97
+ callName : cName ,
98
+ isAsync : true ,
99
+ callType : Object . entries ( calls ) . find ( ( [ _ , value ] ) => value === cName ) ! [ 0 ] ,
100
+ start : start ! ,
101
+ end : end ! ,
102
+ args,
103
+ } )
104
+ }
105
+ }
69
106
} )
70
107
71
108
return nodes
@@ -208,7 +245,7 @@ export function convertQueryToFunctionCall(node: NodeReplacement): string {
208
245
}
209
246
}
210
247
211
- return `${ name } (${ arg } )` . trim ( )
248
+ return `${ node . isAsync ? 'await ' : '' } ${ name } (${ arg } )` . trim ( )
212
249
}
213
250
214
251
/**
0 commit comments