* Extract C/C++ import mappings from #include directives. * * #include brings all symbols from the included header into scope * (namespace import), so each mapping uses isNamespace: true and * exportedName: '*'. The localName is set to the header's basename * without extension so that symbol re
(content: string)
| 1072 | * match against any include that might provide it. |
| 1073 | */ |
| 1074 | function extractCppImports(content: string): ImportMapping[] { |
| 1075 | const mappings: ImportMapping[] = []; |
| 1076 | |
| 1077 | // Match both #include <...> and #include "..." |
| 1078 | const includeRegex = /^\s*#\s*include\s+[<"]([^>"]+)[>"]/gm; |
| 1079 | let match; |
| 1080 | |
| 1081 | while ((match = includeRegex.exec(content)) !== null) { |
| 1082 | const modulePath = match[1]!; |
| 1083 | // Basename without extension for localName matching |
| 1084 | const basename = modulePath.split('/').pop()!.replace(/\.(h|hpp|hxx|hh|inl|ipp|cxx|cc|cpp)$/,''); |
| 1085 | mappings.push({ |
| 1086 | localName: basename || modulePath, |
| 1087 | exportedName: '*', |
| 1088 | source: modulePath, |
| 1089 | isDefault: false, |
| 1090 | isNamespace: true, |
| 1091 | }); |
| 1092 | } |
| 1093 | |
| 1094 | return mappings; |
| 1095 | } |
| 1096 | |
| 1097 | // Cache import mappings per file to avoid re-reading and re-parsing |
| 1098 | const importMappingCache = new Map<string, ImportMapping[]>(); |
no test coverage detected