MCPcopy
hub / github.com/lingodotdev/lingo.dev / getOrCreateImport

Function getOrCreateImport

packages/compiler/src/utils/index.ts:28–58  ·  view source on GitHub ↗
(
  ast: t.Node,
  params: {
    exportedName: string;
    moduleName: string[];
  },
)

Source from the content-addressed store, hash-verified

26}
27
28export 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
60function findExistingImport(
61 ast: t.Node,

Callers 10

jsx-provider.tsFile · 0.90
replaceHtmlComponentFunction · 0.90
jsx-html-lang.tsFile · 0.90
JSXFragmentFunction · 0.90
index.spec.tsFile · 0.90

Calls 3

findExistingImportFunction · 0.85
generateUniqueImportNameFunction · 0.85
createImportDeclarationFunction · 0.85

Tested by

no test coverage detected