1
- import { ASTPath , CallExpression , MemberExpression } from "jscodeshift" ;
2
- import { print } from "recast " ;
1
+ import { ASTPath , CallExpression , JSCodeshift , MemberExpression } from "jscodeshift" ;
2
+ import { emitWarning } from "process " ;
3
3
4
- export const removePromiseForCallExpression = ( callExpression : ASTPath < CallExpression > ) => {
4
+ export const removePromiseForCallExpression = (
5
+ j : JSCodeshift ,
6
+ callExpression : ASTPath < CallExpression >
7
+ ) => {
5
8
switch ( callExpression . parentPath . value . type ) {
6
9
case "MemberExpression" : {
7
10
callExpression . parentPath . value . object = (
8
11
callExpression . value . callee as MemberExpression
9
12
) . object ;
10
13
break ;
11
14
}
15
+ default : {
16
+ emitWarning (
17
+ `Removal of .promise() not implemented for parentPath: ${ callExpression . parentPath . value . type } \n` +
18
+ `Code processed: ${ j ( callExpression . parentPath ) . toSource ( ) } \n\n` +
19
+ "Please report your use case on https://github.com/awslabs/aws-sdk-js-codemod\n"
20
+ ) ;
21
+ const comments = callExpression . parentPath . node . comments || [ ] ;
22
+ comments . push (
23
+ j . commentLine (
24
+ " The promise() call was removed by aws-sdk-js-codemod v2-to-v3 transform using best guess."
25
+ )
26
+ ) ;
27
+ comments . push (
28
+ j . commentLine (
29
+ " Please check that it is correct, and create an issue on GitHub to report this use case."
30
+ )
31
+ ) ;
32
+ callExpression . parentPath . node . comments = comments ;
33
+ }
34
+ // eslint-disable-next-line no-fallthrough
12
35
case "ArrowFunctionExpression" :
13
36
case "AwaitExpression" :
14
37
case "ExpressionStatement" :
@@ -23,11 +46,5 @@ export const removePromiseForCallExpression = (callExpression: ASTPath<CallExpre
23
46
callExpression . value . callee = currentCalleeObject . callee ;
24
47
break ;
25
48
}
26
- default :
27
- throw new Error (
28
- `Removal of .promise() not implemented for parentPath: ${ callExpression . parentPath . value . type } \n` +
29
- `Code processed: ${ print ( callExpression . parentPath . node ) . code } \n\n` +
30
- "Please report your use case on https://github.com/awslabs/aws-sdk-js-codemod\n"
31
- ) ;
32
49
}
33
50
} ;
0 commit comments