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