aws-sdk-js-codemod
Version:
Collection of codemod scripts that help update AWS SDK for JavaScript APIs
43 lines (42 loc) • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getImportSpecifiers = void 0;
const getRequireDeclarators_1 = require("./getRequireDeclarators");
const getImportSpecifiers = (j, source, path) => {
const importSpecifiers = new Set();
for (const varDeclarator of (0, getRequireDeclarators_1.getRequireDeclarators)(j, source, path).nodes()) {
const declaratorId = varDeclarator.id;
const declaratorInit = varDeclarator.init;
if (declaratorId.type === "Identifier") {
const declaratorIdName = declaratorId.name;
if (declaratorInit?.type === "MemberExpression" &&
declaratorInit.property.type === "Identifier") {
importSpecifiers.add({
importedName: declaratorInit.property.name,
localName: declaratorIdName,
});
}
else {
importSpecifiers.add({ localName: declaratorIdName });
}
}
if (declaratorId.type === "ObjectPattern") {
if (declaratorInit?.type !== "CallExpression") {
continue;
}
for (const property of declaratorId.properties) {
if (property.type !== "Property" && property.type !== "ObjectProperty") {
continue;
}
if (property.key.type === "Identifier" && property.value.type === "Identifier") {
importSpecifiers.add({
importedName: property.key.name,
localName: property.value.name,
});
}
}
}
}
return Array.from(importSpecifiers);
};
exports.getImportSpecifiers = getImportSpecifiers;