* The source that declares `root`: `file` itself, or — when `file` is a * barrel (an Nx library's `src/index.ts`) — the module it re-exports it from.
(root: string, file: string, context: ResolutionContext, hops: number)
| 549 | * barrel (an Nx library's `src/index.ts`) — the module it re-exports it from. |
| 550 | */ |
| 551 | function declarationSource(root: string, file: string, context: ResolutionContext, hops: number): string | null { |
| 552 | const content = context.readFile(file); |
| 553 | if (!content) return null; |
| 554 | if (new RegExp(String.raw`\b(?:const|let|class|enum)\s+${escapeRegExp(root)}\b`).test(content)) return content; |
| 555 | if (hops >= 3) return null; |
| 556 | const reexports = /\bexport\s+(\*|\{[^}]*\})\s*from\s+(['"])([^'"]+)\2/g; |
| 557 | let m: RegExpExecArray | null; |
| 558 | while ((m = reexports.exec(content)) !== null) { |
| 559 | if (m[1] !== '*' && !new RegExp(String.raw`\b${escapeRegExp(root)}\b`).test(m[1]!)) continue; |
| 560 | const target = resolveImportPath(m[3]!, file, 'typescript', context); |
| 561 | const found = target ? declarationSource(root, target, context, hops + 1) : null; |
| 562 | if (found) return found; |
| 563 | } |
| 564 | return null; |
| 565 | } |
| 566 | |
| 567 | /** `create.path` as the chain its root was destructured from in `fromFile`, or null when the root is no local alias. */ |
| 568 | function localAlias(expr: string, fromFile: string, context: ResolutionContext): string | null { |
no test coverage detected