* Resolve a CALL through an imported value to the method on the value's own * type: `reproStore.notifyJoinGuildStatus()` where `reproStore` is * `export const reproStore = new ReproStore()` in the imported file (#1292). * The same-file form of this call already resolves via local-variable * rece
( value: Node, ref: UnresolvedRef, localName: string, context: ResolutionContext )
| 4684 | * caller keeps its existing constant-edge behavior. |
| 4685 | */ |
| 4686 | function resolveImportedInstanceMember( |
| 4687 | value: Node, |
| 4688 | ref: UnresolvedRef, |
| 4689 | localName: string, |
| 4690 | context: ResolutionContext |
| 4691 | ): ResolvedRef | null { |
| 4692 | if (ref.referenceKind !== 'calls') return null; |
| 4693 | if (value.kind !== 'constant' && value.kind !== 'variable') return null; |
| 4694 | // The method called on the value itself: `app.jinja_env.filters.keys()` |
| 4695 | // calls `keys`, no method of the app's type — never `jinja_env`. |
| 4696 | const member = ref.referenceName.slice(localName.length + 1); |
| 4697 | if (!member || member.includes('.')) return null; |
| 4698 | |
| 4699 | const source = context.readFile(value.filePath); |
| 4700 | if (!source) return null; |
| 4701 | // Only the value's own declaration lines — never the whole file, so a |
| 4702 | // same-named identifier elsewhere can't donate a type. |
| 4703 | const lines = source.split('\n'); |
| 4704 | const declSlice = lines.slice(Math.max(0, value.startLine - 1), value.endLine).join('\n'); |
| 4705 | |
| 4706 | const receiver = value.name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); |
| 4707 | for (const pattern of localReceiverTypePatterns(value.language as Language, receiver)) { |
| 4708 | const m = declSlice.match(pattern); |
| 4709 | if (!m || !m[1]) continue; |
| 4710 | const typeName = normalizeInferredTypeName(m[1]); |
| 4711 | if (!typeName) continue; |
| 4712 | // Several classes may share the name. The value's file says which one: |
| 4713 | // the class it imports under that name, or else the one it declares. |
| 4714 | const declaring = ESM_IMPORT_LANGUAGES.has(value.language) |
| 4715 | ? tsImportedTypeFile(m[1], { ...ref, filePath: value.filePath, language: value.language }, context) ?? value.filePath |
| 4716 | : undefined; |
| 4717 | const resolved = resolveMethodOnType(typeName, member, ref, context, 0.85, 'instance-method', declaring); |
| 4718 | if (resolved) return resolved; |
| 4719 | } |
| 4720 | return null; |
| 4721 | } |
| 4722 | |
| 4723 | function resolveStaticMember( |
| 4724 | container: Node, |
no test coverage detected