* 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)
| 3101 | * puts it. |
| 3102 | */ |
| 3103 | function typeQualifier(ref: UnresolvedRef, context: ResolutionContext): string[] | null { |
| 3104 | const line = context.getFileLines?.(ref.filePath)?.[ref.line - 1] ?? context.readFile(ref.filePath)?.split(/\r?\n/)[ref.line - 1]; |
| 3105 | if (!line?.startsWith(ref.referenceName, ref.column)) return null; |
| 3106 | const names: string[] = []; |
| 3107 | let i = ref.column - 1; |
| 3108 | for (;;) { |
| 3109 | while (i >= 0 && (line[i] === ' ' || line[i] === '\t')) i--; |
| 3110 | if (line[i] !== '.') break; |
| 3111 | i--; |
| 3112 | while (i >= 0 && (line[i] === ' ' || line[i] === '\t')) i--; |
| 3113 | const end = i + 1; |
| 3114 | while (i >= 0 && /[\w$]/.test(line[i]!)) i--; |
| 3115 | const name = line.slice(i + 1, end); |
| 3116 | if (!/^[A-Za-z_$][\w$]*$/.test(name)) return null; |
| 3117 | names.unshift(name); |
| 3118 | } |
| 3119 | return names.length > 0 ? names : null; |
| 3120 | } |
| 3121 | |
| 3122 | /** |
| 3123 | * A type path through an import of the file's: the module's export the path |
no test coverage detected