* Extract Go import mappings
(content: string)
| 953 | * Extract Go import mappings |
| 954 | */ |
| 955 | function extractGoImports(content: string): ImportMapping[] { |
| 956 | const mappings: ImportMapping[] = []; |
| 957 | |
| 958 | // import "path" or import alias "path" |
| 959 | const singleImportRegex = /import\s+(?:(\w+)\s+)?["']([^"']+)["']/g; |
| 960 | let match; |
| 961 | |
| 962 | while ((match = singleImportRegex.exec(content)) !== null) { |
| 963 | const [, alias, source] = match; |
| 964 | const packageName = source!.split('/').pop()!; |
| 965 | mappings.push({ |
| 966 | localName: alias || packageName, |
| 967 | exportedName: '*', |
| 968 | source: source!, |
| 969 | isDefault: false, |
| 970 | isNamespace: true, |
| 971 | }); |
| 972 | } |
| 973 | |
| 974 | // import ( ... ) block |
| 975 | const blockImportRegex = /import\s*\(\s*([^)]+)\s*\)/gs; |
| 976 | while ((match = blockImportRegex.exec(content)) !== null) { |
| 977 | const block = match[1]!; |
| 978 | const lineRegex = /(?:(\w+)\s+)?["']([^"']+)["']/g; |
| 979 | let lineMatch; |
| 980 | |
| 981 | while ((lineMatch = lineRegex.exec(block)) !== null) { |
| 982 | const [, alias, source] = lineMatch; |
| 983 | const packageName = source!.split('/').pop()!; |
| 984 | mappings.push({ |
| 985 | localName: alias || packageName, |
| 986 | exportedName: '*', |
| 987 | source: source!, |
| 988 | isDefault: false, |
| 989 | isNamespace: true, |
| 990 | }); |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | return mappings; |
| 995 | } |
| 996 | |
| 997 | /** |
| 998 | * Extract Java / Kotlin import mappings. |
no test coverage detected