UNPKG

@yandex/ui

Version:

Yandex UI components

50 lines (43 loc) 1.97 kB
module.exports = (fileInfo, { jscodeshift: j }) => { const root = j(fileInfo.source); const withBemModImport = root.find(j.ImportSpecifier).filter((nodePath) => { return nodePath.value.imported.name === 'withBemMod'; }); if (withBemModImport.length === 1) { root.find(j.CallExpression) .filter((nodePath) => { if (nodePath.value.callee.name !== 'withBemMod') { return false; } if (nodePath.value.arguments[1].properties.length !== 1) { return false; } if (nodePath.value.arguments.length !== 2) { return false; } return true; }) .forEach((nodePath) => { const typeParams = nodePath.value.typeParameters; let TypeToRemove = null; if (typeParams && typeParams.params.length === 2) { TypeToRemove = typeParams.params[1].typeName.name; typeParams.params = typeParams.params.slice(0, 1); } nodePath.value.callee.name = 'createClassNameModifier'; withBemModImport.forEach((nodePath) => (nodePath.value.imported.name = 'createClassNameModifier')); if (TypeToRemove) { root.find(j.ImportDeclaration).forEach((nodePath) => { let { specifiers } = nodePath.value; if (!specifiers || !specifiers.length) return; specifiers = nodePath.value.specifiers.filter((s) => s.local.name !== TypeToRemove); nodePath.value.specifiers = specifiers; if (specifiers.length === 0) { j(nodePath).remove(); } }); } }); } return root.toSource(); };