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 " ;
33
4- export const removePromiseForCallExpression = ( callExpression : ASTPath < CallExpression > ) => {
4+ export const removePromiseForCallExpression = (
5+ j : JSCodeshift ,
6+ callExpression : ASTPath < CallExpression >
7+ ) => {
58 switch ( callExpression . parentPath . value . type ) {
69 case "MemberExpression" : {
710 callExpression . parentPath . value . object = (
811 callExpression . value . callee as MemberExpression
912 ) . object ;
1013 break ;
1114 }
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
1235 case "ArrowFunctionExpression" :
1336 case "AwaitExpression" :
1437 case "ExpressionStatement" :
@@ -23,11 +46,5 @@ export const removePromiseForCallExpression = (callExpression: ASTPath<CallExpre
2346 callExpression . value . callee = currentCalleeObject . callee ;
2447 break ;
2548 }
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- ) ;
3249 }
3350} ;
0 commit comments