import { Collection , JSCodeshift , CallExpression } from 'jscodeshift' ; export function getImportRenameMap ( j , root , packageName = '' ) { let containsCanvasImports = false ; const importMap = { } ; const styledMap = { } ; root . find ( j . ImportDeclaration , node => { const value = node . source . value ; if ( typeof value === 'string' && ( value === '@workday/canvas-kit-react' || value === packageName ) ) { containsCanvasImports = true ; ( node . specifiers || [ ] ) . forEach ( specifier => { if ( specifier . type === 'ImportSpecifier' ) { if ( ! specifier . local || specifier . local . name === specifier . imported . name ) { importMap [ specifier . imported . name ] = specifier . imported . name ; } else { importMap [ specifier . imported . name ] = specifier . local . name ; } } } ) ; } return false ; } ) ; root . find ( j . CallExpression , ( node ) => { if ( node . callee . type === 'Identifier' && node . callee . name === 'styled' && node . arguments [ 0 ] . type === 'Identifier' ) { return true ; } return false ; } ) . forEach ( nodePath => { if ( ( nodePath . parent . value . type === 'CallExpression' || nodePath . parent . value . type === 'TaggedTemplateExpression' ) && nodePath . parent . parent . value . type === 'VariableDeclarator' && nodePath . parent . parent . value . id . type === 'Identifier' ) { const styledName = nodePath . parent . parent . value . id . name ; if ( nodePath . value . arguments [ 0 ] . type === 'Identifier' ) { styledMap [ nodePath . value . arguments [ 0 ] . name ] = styledName ; } } } ) ; return { containsCanvasImports , importMap , styledMap } ; }