import type * as d from '../../declarations' ; import { dirname , resolve } from 'path' ; param importDataObj param cmpMeta param filePath param config export const updateReferenceTypeImports = ( importDataObj , allTypes , cmp , filePath ) => { const updateImportReferences = updateImportReferenceFactory ( allTypes , filePath ) ; return [ ... cmp . properties , ... cmp . events , ... cmp . methods ] . filter ( ( cmpProp ) => cmpProp . complexType && cmpProp . complexType . references ) . reduce ( ( obj , cmpProp ) => { return updateImportReferences ( obj , cmpProp . complexType . references ) ; } , importDataObj ) ; } ; const updateImportReferenceFactory = ( allTypes , filePath ) => { function getIncrementTypeName ( name ) { const counter = allTypes . get ( name ) ; if ( counter === undefined ) { allTypes . set ( name , 1 ) ; return name ; } allTypes . set ( name , counter + 1 ) ; return `${ name }${ counter }` ; } return ( obj , typeReferences ) => { Object . keys ( typeReferences ) . map ( ( typeName ) => { return [ typeName , typeReferences [ typeName ] ] as [ string , d . ComponentCompilerTypeReference ] ; } ) . forEach ( ( [ typeName , type ] ) => { let importFileLocation ; if ( type . location === 'global' ) { return ; } else if ( type . location === 'local' ) { importFileLocation = filePath ; } else if ( type . location === 'import' ) { importFileLocation = type . path ; } if ( importFileLocation . startsWith ( '.' ) ) { importFileLocation = resolve ( dirname ( filePath ) , importFileLocation ) ; } obj [ importFileLocation ] = obj [ importFileLocation ] || [ ] ; if ( obj [ importFileLocation ] . find ( ( df ) => df . localName === typeName ) ) { return ; } const newTypeName = getIncrementTypeName ( typeName ) ; obj [ importFileLocation ] . push ( { localName : typeName , importName : newTypeName , } ) ; } ) ; return obj ; } ; } ;