UNPKG

aws-sdk-js-codemod

Version:

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

20 lines (19 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.removeImportEquals = void 0; const removeDeclaration_1 = require("../removeDeclaration"); const getImportEqualsDeclarations_1 = require("./getImportEqualsDeclarations"); const isAnotherSpecifier = (j, source, localName) => source.find(j.TSImportEqualsDeclaration, { id: { name: localName } }).size() > 1; const removeImportEquals = (j, source) => (0, getImportEqualsDeclarations_1.getImportEqualsDeclarations)(j, source).forEach((importEqualsDeclaration) => { const localName = importEqualsDeclaration.value.id.name; if (typeof localName !== "string") { throw new Error("Please report your use case on https://github.com/aws/aws-sdk-js-codemod"); } const identifiers = source.find(j.Identifier, { name: localName }); // Either the identifier is the only occurence on the page. // Or there is another specifier with the same name imported from JS SDK v3. if (identifiers.size() === 1 || isAnotherSpecifier(j, source, localName)) { (0, removeDeclaration_1.removeDeclaration)(j, source, importEqualsDeclaration.get()); } }); exports.removeImportEquals = removeImportEquals;