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)
| 908 | |
| 909 | /** The include files a Pascal file pulls in (`{$I name.inc}`, `{$INCLUDE name}`), each the one of that name nearest it. */ |
| 910 | function includesOf(filePath: string, context: ResolutionContext): string[] { |
| 911 | const m = memos(context); |
| 912 | let includes = m.includes.get(filePath); |
| 913 | if (includes) return includes; |
| 914 | includes = []; |
| 915 | if (PASCAL_SOURCE.test(filePath)) { |
| 916 | for (const text of fileLines(filePath, context)) { |
| 917 | if (!text.includes('{$') || !/\{\$i(?:nclude)?\s/i.test(text)) continue; |
| 918 | for (const match of text.matchAll(/\{\$(?:I|INCLUDE)\s+['"]?([^'"}\s*]+)/gi)) { |
| 919 | let name = match[1]!.replace(/\\/g, '/'); |
| 920 | name = name.slice(name.lastIndexOf('/') + 1).toLowerCase(); |
| 921 | if (!name.includes('.')) name += '.inc'; |
| 922 | const inc = nearest(projectFiles(context).byName.get(name) ?? [], filePath); |
| 923 | if (inc && inc !== filePath && !includes.includes(inc)) includes.push(inc); |
| 924 | } |
| 925 | } |
| 926 | } |
| 927 | m.includes.set(filePath, includes); |
| 928 | return includes; |
| 929 | } |
| 930 | |
| 931 | /** The Pascal file that includes an include file: of the forty nearest it, the nearest whose text does. */ |
| 932 | function includerOf(incFile: string, context: ResolutionContext): string | null { |