UNPKG

aws-sdk-js-codemod

Version:

Collection of codemod scripts that help update AWS SDK for JavaScript APIs

25 lines (24 loc) 978 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addEmptyObjectForUndefined = void 0; // Adds an empty object, if undefined is passed for optional parameters. const addEmptyObjectForUndefined = (j, source, clientIdentifiers) => { for (const clientId of clientIdentifiers) { source .find(j.CallExpression, { callee: { type: "MemberExpression", object: clientId, }, }) .filter((callExpression) => { return (callExpression.value.arguments.length === 1 && ["FunctionExpression", "ArrowFunctionExpression"].includes(callExpression.value.arguments[0].type)); }) .replaceWith((callExpression) => { callExpression.value.arguments.unshift(j.objectExpression([])); return callExpression.value; }); } }; exports.addEmptyObjectForUndefined = addEmptyObjectForUndefined;