* Resolve a CFML inheritance reference written as a component path (#1152). * Two forms exist in real code: * * - Dotted: `extends="coldbox.system.web.Controller"` — dots are directory * separators from the webroot or a CFML mapping. Mappings live in server * config / Application.
(ref: UnresolvedRef)
| 3952 | * corroborates, and the file must be named like the component. |
| 3953 | */ |
| 3954 | private resolveCfmlComponentPath(ref: UnresolvedRef): ResolvedRef | null { |
| 3955 | const cfmlCandidates = (name: string): Node[] => |
| 3956 | this.context |
| 3957 | .getNodesByName(name) |
| 3958 | .filter( |
| 3959 | (n) => |
| 3960 | (n.kind === 'class' || n.kind === 'interface') && |
| 3961 | (n.language === 'cfml' || n.language === 'cfscript') |
| 3962 | ); |
| 3963 | const norm = (p: string): string => p.replace(/\\/g, '/').toLowerCase(); |
| 3964 | |
| 3965 | // Relative-path form: `../base`, `./base`, `sub/thing` — resolve against |
| 3966 | // the referencing file's directory and require an exact (case-insensitive) |
| 3967 | // file match. |
| 3968 | if (ref.referenceName.includes('/')) { |
| 3969 | const rel = ref.referenceName.replace(/\.cfc$/i, ''); |
| 3970 | const fromDir = ref.filePath.replace(/\\/g, '/').split('/').slice(0, -1); |
| 3971 | const parts = [...fromDir]; |
| 3972 | for (const seg of rel.split('/')) { |
| 3973 | if (seg === '' || seg === '.') continue; |
| 3974 | if (seg === '..') { |
| 3975 | if (parts.length === 0) return null; // escapes the project root |
| 3976 | parts.pop(); |
| 3977 | } else { |
| 3978 | parts.push(seg); |
| 3979 | } |
| 3980 | } |
| 3981 | const wantPath = norm(parts.join('/') + '.cfc'); |
| 3982 | const className = parts[parts.length - 1]; |
| 3983 | if (!className) return null; |
| 3984 | const target = cfmlCandidates(className).find((c) => norm(c.filePath) === wantPath); |
| 3985 | return target |
| 3986 | ? { original: ref, targetNodeId: target.id, confidence: 0.95, resolvedBy: 'file-path' } |
| 3987 | : null; |
| 3988 | } |
| 3989 | |
| 3990 | // Dotted form. |
| 3991 | const segments = ref.referenceName.split('.').map((s) => s.trim()).filter(Boolean); |
| 3992 | if (segments.length < 2) return null; |
| 3993 | const className = segments[segments.length - 1]!; |
| 3994 | const dirSegments = segments.slice(0, -1); |
| 3995 | |
| 3996 | // Production code never names a component in a test suite; a test can |
| 3997 | // name one, by the path to it. |
| 3998 | const fromTest = isTestPath(ref.filePath); |
| 3999 | let bestScore = 0; |
| 4000 | let tied: Node[] = []; |
| 4001 | for (const cand of cfmlCandidates(className)) { |
| 4002 | if (!fromTest && isTestSuitePath(cand.filePath)) continue; |
| 4003 | const dirs = cand.filePath.replace(/\\/g, '/').split('/').slice(0, -1); |
| 4004 | // Count matching directory segments right-to-left: for |
| 4005 | // `coldbox.system.web.Controller` vs `system/web/Controller.cfc`, |
| 4006 | // `web` and `system` match, then the repo root ends the run → score 2. |
| 4007 | let score = 0; |
| 4008 | while ( |
| 4009 | score < dirSegments.length && |
| 4010 | score < dirs.length && |
| 4011 | dirSegments[dirSegments.length - 1 - score]!.toLowerCase() === |
no test coverage detected