(filePath: string, context: ResolutionContext)
| 120 | const fileExportIndexes = new WeakMap<ResolutionContext, Map<string, FileExportIndex>>(); |
| 121 | |
| 122 | function getFileExportIndex(filePath: string, context: ResolutionContext): FileExportIndex { |
| 123 | let perFile = fileExportIndexes.get(context); |
| 124 | if (!perFile) { |
| 125 | perFile = new Map(); |
| 126 | fileExportIndexes.set(context, perFile); |
| 127 | } |
| 128 | let idx = perFile.get(filePath); |
| 129 | if (!idx) { |
| 130 | idx = { byName: new Map(), defaultComponent: undefined, defaultFnClass: undefined }; |
| 131 | const exported = context.getExportedNodesInFile?.(filePath) ?? context.getNodesInFile(filePath).filter((n) => n.isExported); |
| 132 | for (const n of exported) { |
| 133 | if (!idx.byName.has(n.name)) idx.byName.set(n.name, n); |
| 134 | if (idx.defaultComponent === undefined && n.kind === 'component') idx.defaultComponent = n; |
| 135 | if (idx.defaultFnClass === undefined && (n.kind === 'function' || n.kind === 'class')) idx.defaultFnClass = n; |
| 136 | } |
| 137 | perFile.set(filePath, idx); |
| 138 | } |
| 139 | return idx; |
| 140 | } |
| 141 | |
| 142 | /** The file's nodes named `name`, in `getNodesInFile` order. */ |
| 143 | function nodesInFileNamed(filePath: string, name: string, context: ResolutionContext): Node[] { |
no test coverage detected