* The names a type's last name was written after, first to last: `['React']` * for `React.ReactNode`, `['a', 'b']` for `a.b.C`. Null for a name written * alone, after an expression (`import('./x').T`), or not where the reference * puts it.
(ref: UnresolvedRef, context: ResolutionContext)
| 3000 | * puts it. |
| 3001 | */ |
| 3002 | function typeQualifier(ref: UnresolvedRef, context: ResolutionContext): string[] | null { |
| 3003 | const line = context.getFileLines?.(ref.filePath)?.[ref.line - 1] ?? context.readFile(ref.filePath)?.split(/\r?\n/)[ref.line - 1]; |
| 3004 | if (!line?.startsWith(ref.referenceName, ref.column)) return null; |
| 3005 | const names: string[] = []; |
| 3006 | let i = ref.column - 1; |
| 3007 | for (;;) { |
| 3008 | while (i >= 0 && (line[i] === ' ' || line[i] === '\t')) i--; |
| 3009 | if (line[i] !== '.') break; |
| 3010 | i--; |
| 3011 | while (i >= 0 && (line[i] === ' ' || line[i] === '\t')) i--; |
| 3012 | const end = i + 1; |
| 3013 | while (i >= 0 && /[\w$]/.test(line[i]!)) i--; |
| 3014 | const name = line.slice(i + 1, end); |
| 3015 | if (!/^[A-Za-z_$][\w$]*$/.test(name)) return null; |
| 3016 | names.unshift(name); |
| 3017 | } |
| 3018 | return names.length > 0 ? names : null; |
| 3019 | } |
| 3020 | |
| 3021 | /** |
| 3022 | * A type path through an import of the file's: the module's export the path |
no test coverage detected