( file: string, quote: string, spec: string, language: UnresolvedRef['language'], context: ResolutionContext, cache: Cache )
| 246 | } |
| 247 | |
| 248 | function resolveInclude( |
| 249 | file: string, |
| 250 | quote: string, |
| 251 | spec: string, |
| 252 | language: UnresolvedRef['language'], |
| 253 | context: ResolutionContext, |
| 254 | cache: Cache |
| 255 | ): string | null { |
| 256 | const key = `${language}\0${file}\0${quote}${spec}`; |
| 257 | const cached = cache.includes.get(key); |
| 258 | if (cached !== undefined) return cached; |
| 259 | const local = path.posix.normalize(path.posix.join(path.posix.dirname(file), spec.replace(/\\/g, '/'))); |
| 260 | let target = |
| 261 | quote === '"' && !local.startsWith('../') && !path.posix.isAbsolute(local) && context.fileExists(local) |
| 262 | ? local |
| 263 | : resolveImportPath(spec, file, language, context); |
| 264 | if (!target) { |
| 265 | if (!cache.byBasename) { |
| 266 | cache.byBasename = new Map(); |
| 267 | for (const f of context.getAllFiles()) { |
| 268 | const base = f.slice(f.lastIndexOf('/') + 1); |
| 269 | const list = cache.byBasename.get(base); |
| 270 | if (list) list.push(f); |
| 271 | else cache.byBasename.set(base, [f]); |
| 272 | } |
| 273 | } |
| 274 | const normalized = spec.replace(/\\/g, '/'); |
| 275 | const matches = (cache.byBasename.get(normalized.slice(normalized.lastIndexOf('/') + 1)) ?? []).filter( |
| 276 | (f) => f === normalized || f.endsWith('/' + normalized) |
| 277 | ); |
| 278 | if (matches.length === 1) target = matches[0]!; |
| 279 | } |
| 280 | cache.includes.set(key, target); |
| 281 | return target; |
| 282 | } |
| 283 | |
| 284 | function walkTranslationUnit( |
| 285 | rootFile: string, |
no test coverage detected