* The helper for a class that applies in a file: of those its unit declares * or uses, its own unit's, else the one of the unit it uses last, the one * declared last of them. Null when none does.
(cls: Node, fromFile: string, context: ResolutionContext)
| 2033 | * declared last of them. Null when none does. |
| 2034 | */ |
| 2035 | function nearestHelper(cls: Node, fromFile: string, context: ResolutionContext): Node | null { |
| 2036 | const helpers = helpersByType(context).get(cls.id); |
| 2037 | if (!helpers) return null; |
| 2038 | const own = ownUnitFiles(fromFile, context); |
| 2039 | const used = usedUnitFiles(fromFile, context); |
| 2040 | // How near a helper's unit is: its own unit's nearest, then the units used last. |
| 2041 | const rank = (file: string): number => (own.includes(file) ? Infinity : used.indexOf(file)); |
| 2042 | return helpers.filter((h) => rank(h.filePath) >= 0) |
| 2043 | .sort((a, b) => rank(b.filePath) - rank(a.filePath) || b.startLine - a.startLine)[0] ?? null; |
| 2044 | } |
| 2045 | |
| 2046 | /** A member a helper declares, or one of the helpers it descends from. */ |
| 2047 | function helperChainMember(helper: Node | null, lower: string, context: ResolutionContext): Node | null { |
no test coverage detected