import { API , FileInfo , Options , JSXIdentifier } from 'jscodeshift' ; import { getImportRenameMap } from './getImportRenameMap' ; const buttonNames = [ 'Button' , 'DeleteButton' , 'deprecated_Button' , 'DropdownButton' , 'HighlightButton' , 'Hyperlink' , 'IconButton' , 'OutlineButton' , 'TextButton' , 'ToolbarDropdownButton' , 'ToolbarIconButton' , ] ; export default function transformer ( file , api , options ) { const j = api . jscodeshift ; const root = j ( file . source ) ; const { containsCanvasImports , importMap } = getImportRenameMap ( j , root , '@workday/canvas-kit-react/button' ) ; if ( ! containsCanvasImports ) { return file . source ; } root . find ( j . JSXIdentifier , ( value ) => value . name === 'buttonRef' ) . replaceWith ( nodePath => { const elementName = nodePath . parent ?. parent ?. value ?. name ?. name ; if ( buttonNames . map ( n => importMap [ n ] ) . includes ( elementName ) ) { return j . jsxIdentifier ( 'ref' ) ; } return nodePath . value ; } ) ; return root . toSource ( ) ; }