aws-sdk-js-codemod
Version:
Collection of codemod scripts that help update AWS SDK for JavaScript APIs
41 lines (40 loc) • 2.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.removePromiseForCallExpression = void 0;
const node_process_1 = require("node:process");
const removePromiseForCallExpression = (j, callExpression) => {
const parentPathValue = Array.isArray(callExpression.parentPath.value)
? callExpression.parentPath.value[0]
: callExpression.parentPath.value;
switch (parentPathValue.type) {
case "MemberExpression": {
callExpression.parentPath.value.object = callExpression.value.callee.object;
break;
}
case "ArrowFunctionExpression":
case "AwaitExpression":
case "CallExpression":
case "ExpressionStatement":
case "ObjectProperty":
case "ReturnStatement":
case "VariableDeclarator": {
const currentCalleeObject = callExpression.value.callee
.object;
if (currentCalleeObject.arguments.length > 0) {
callExpression.value.arguments = currentCalleeObject.arguments;
}
callExpression.value.callee = currentCalleeObject.callee;
break;
}
default: {
(0, node_process_1.emitWarning)(`Removal of .promise() not implemented for parentPath: ${callExpression.parentPath.value.type}\n` +
`Code processed: ${j(callExpression.parentPath).toSource()}\n\n` +
"Please report your use case on https://github.com/aws/aws-sdk-js-codemod\n");
const comments = callExpression.parentPath.node.comments || [];
comments.push(j.commentLine(" The promise() call was removed by aws-sdk-js-codemod v2-to-v3 transform using best guess."));
comments.push(j.commentLine(" Please check that it is correct, and create an issue on GitHub to report this use case."));
callExpression.parentPath.node.comments = comments;
}
}
};
exports.removePromiseForCallExpression = removePromiseForCallExpression;