The include files a Pascal file pulls in (`{$I name.inc}`, `{$INCLUDE name}`), each the one of that name nearest it.
(filePath: string, context: ResolutionContext)
| 2444 | |
| 2445 | /** The include files a Pascal file pulls in (`{$I name.inc}`, `{$INCLUDE name}`), each the one of that name nearest it. */ |
| 2446 | function includesOf(filePath: string, context: ResolutionContext): string[] { |
| 2447 | const m = memos(context); |
| 2448 | let includes = m.includes.get(filePath); |
| 2449 | if (includes) return includes; |
| 2450 | includes = []; |
| 2451 | if (PASCAL_SOURCE.test(filePath)) { |
| 2452 | for (const text of fileLines(filePath, context)) { |
| 2453 | if (!text.includes('{$') || !/\{\$i(?:nclude)?\s/i.test(text)) continue; |
| 2454 | for (const match of text.matchAll(/\{\$(?:I|INCLUDE)\s+['"]?([^'"}\s*]+)/gi)) { |
| 2455 | let name = match[1]!.replace(/\\/g, '/'); |
| 2456 | name = name.slice(name.lastIndexOf('/') + 1).toLowerCase(); |
| 2457 | if (!name.includes('.')) name += '.inc'; |
| 2458 | const inc = nearest(projectFiles(context).byName.get(name) ?? [], filePath); |
| 2459 | if (inc && inc !== filePath && !includes.includes(inc)) includes.push(inc); |
| 2460 | } |
| 2461 | } |
| 2462 | } |
| 2463 | m.includes.set(filePath, includes); |
| 2464 | return includes; |
| 2465 | } |
| 2466 | |
| 2467 | /** The Pascal file that includes an include file: of the forty nearest it, the nearest whose text does. */ |
| 2468 | function includerOf(incFile: string, context: ResolutionContext): string | null { |