3
3
* It won't modify your file
4
4
*/
5
5
6
- import {
7
- FileInfo ,
8
- API ,
9
- Options ,
10
- ASTPath ,
11
- Collection ,
12
- MemberExpression ,
13
- CallExpression ,
14
- ExpressionStatement ,
15
- FunctionDeclaration ,
16
- ArrowFunctionExpression ,
17
- FunctionExpression ,
18
- Position ,
19
- } from "jscodeshift" ;
20
-
21
- const methodsMapping = {
22
- findOne : "findOneAsync" ,
23
- insert : "insertAsync" ,
24
- upsert : "upsertAsync" ,
25
- update : "updateAsync" ,
26
- remove : "removeAsync" ,
27
- createIndex : "createIndexAsync" ,
28
- dropIndex : "dropIndexAsync" ,
29
- dropCollection : "dropCollectionAsync" ,
30
- // methods on cursors
31
- count : "countAsync" ,
32
- fetch : "fetchAsync" ,
33
- forEach : "forEachAsync" ,
34
- map : "mapAsync" ,
35
- } ;
36
-
37
- import {
38
- addAwaitKeyword ,
39
- findParentFunction ,
40
- getFunctionLocation ,
41
- setFunctionNotAsync ,
42
- } from "./utils" ;
6
+ import { FileInfo , API , Options } from "jscodeshift" ;
43
7
44
8
const debug = require ( "debug" ) ( "transform:find-promise-all-foreach" ) ;
9
+ const debug2 = require ( "debug" ) ( "transform:print:find-promise-all-foreach" ) ;
45
10
46
11
module . exports = function ( fileInfo : FileInfo , { j } : API , options : Options ) {
47
- // debug(
48
- // `**************************************************
49
- // *** ${fileInfo.path}
50
- // **************************************************`
51
- // );
12
+ debug (
13
+ `**************************************************
14
+ *** ${ fileInfo . path }
15
+ **************************************************`
16
+ ) ;
52
17
53
18
const rootCollection = j ( fileInfo . source ) ;
54
19
// debug(rootCollection)
55
20
56
21
// find all Promise.all() call
57
22
rootCollection . find ( j . CallExpression ) . map ( ( p ) => {
58
- // debug(j(p).toSource(), p.value.callee);
23
+ debug ( j ( p ) . toSource ( ) , p . value . callee ) ;
59
24
if ( p . value . callee . type === "MemberExpression" ) {
60
25
const { object, property } = p . value . callee ;
61
26
if (
@@ -65,21 +30,21 @@ module.exports = function (fileInfo: FileInfo, { j }: API, options: Options) {
65
30
property . type === "Identifier" &&
66
31
property . name === "all"
67
32
) {
68
- // debug("child", p.value.arguments);
33
+ debug ( "child" , p . value . arguments ) ;
69
34
if (
70
35
p . value . arguments [ 0 ] &&
71
36
p . value . arguments [ 0 ] . type === "CallExpression"
72
37
) {
73
38
if ( p . value . arguments [ 0 ] . callee . type === "MemberExpression" ) {
74
39
const { property : cProperty } = p . value . arguments [ 0 ] . callee ;
75
- // debug(cProperty);
40
+ debug ( cProperty ) ;
76
41
if (
77
42
cProperty . type === "Identifier" &&
78
43
cProperty . name === "forEach"
79
44
) {
80
45
// found
81
46
debug ( fileInfo . path ) ;
82
- debug ( "!!!FOUND" , cProperty . loc ?. start ) ;
47
+ debug2 ( "!!!FOUND" , cProperty . loc ?. start ) ;
83
48
// debug(j(p).toSource());
84
49
}
85
50
}
0 commit comments