(
ast: t.Node,
params: {
exportedName: string;
moduleName: string[];
},
)
| 26 | } |
| 27 | |
| 28 | export function getOrCreateImport( |
| 29 | ast: t.Node, |
| 30 | params: { |
| 31 | exportedName: string; |
| 32 | moduleName: string[]; |
| 33 | }, |
| 34 | ): { importedName: string } { |
| 35 | let importedName = params.exportedName; |
| 36 | let existingImport = findExistingImport( |
| 37 | ast, |
| 38 | params.exportedName, |
| 39 | params.moduleName, |
| 40 | ); |
| 41 | |
| 42 | if (existingImport) { |
| 43 | return { importedName: existingImport }; |
| 44 | } |
| 45 | |
| 46 | // Find a unique import name if needed |
| 47 | importedName = generateUniqueImportName(ast, params.exportedName); |
| 48 | |
| 49 | // Create the import declaration |
| 50 | createImportDeclaration( |
| 51 | ast, |
| 52 | importedName, |
| 53 | params.exportedName, |
| 54 | params.moduleName, |
| 55 | ); |
| 56 | |
| 57 | return { importedName }; |
| 58 | } |
| 59 | |
| 60 | function findExistingImport( |
| 61 | ast: t.Node, |
no test coverage detected