(ref, context)
| 578 | }, |
| 579 | |
| 580 | resolve(ref, context) { |
| 581 | // We only redirect JS callers — native callers don't need this resolver. |
| 582 | if ( |
| 583 | ref.language !== 'javascript' && |
| 584 | ref.language !== 'typescript' && |
| 585 | ref.language !== 'tsx' && |
| 586 | ref.language !== 'jsx' |
| 587 | ) { |
| 588 | return null; |
| 589 | } |
| 590 | |
| 591 | // JS callsites of `obj.method()` reach the resolver as either |
| 592 | // `obj.method` (qualified) or `method` (bare). Strip the receiver to |
| 593 | // get the JS-visible method name — and keep it, as evidence. |
| 594 | const raw = ref.referenceName; |
| 595 | const lastDot = raw.lastIndexOf('.'); |
| 596 | const name = lastDot >= 0 ? raw.slice(lastDot + 1) : raw; |
| 597 | |
| 598 | const maps = buildRNMaps(context); |
| 599 | const entries = maps.byJsName.get(name); |
| 600 | if (!entries || entries.length === 0) return null; |
| 601 | |
| 602 | // iOS first — the conventional first-class platform for RN library docs |
| 603 | // and most graph queries; one edge is recorded either way. |
| 604 | const pick = (list: NativeMethod[]): NativeMethod | undefined => |
| 605 | list.find((e) => e.node.language === 'objc') ?? |
| 606 | list.find((e) => e.node.language === 'swift') ?? |
| 607 | list[0]; |
| 608 | |
| 609 | // Receiver evidence: `NativeModules.Mod.method`, or an alias the project |
| 610 | // bound to `NativeModules.Mod`. The module is named, so the match is to |
| 611 | // THAT module's method at a confidence the import resolver cannot beat |
| 612 | // — and a module that has no such method is not ours to guess at. |
| 613 | if (lastDot >= 0) { |
| 614 | const receiver = raw.slice(0, lastDot); |
| 615 | const direct = receiver.match(/^NativeModules\.([A-Z][\w$]*)$/); |
| 616 | const moduleName = direct ? direct[1]! : maps.aliases.get(receiver) ?? null; |
| 617 | if (moduleName !== null) { |
| 618 | const exact = pick(entries.filter((e) => e.moduleName === moduleName)); |
| 619 | if (!exact) return null; |
| 620 | return { |
| 621 | original: ref, |
| 622 | targetNodeId: exact.node.id, |
| 623 | confidence: 0.95, |
| 624 | resolvedBy: 'framework', |
| 625 | metadata: { bridge: 'react-native', module: moduleName }, |
| 626 | }; |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | const target = pick(entries); |
| 631 | if (!target) return null; |
| 632 | return { |
| 633 | original: ref, |
| 634 | targetNodeId: target.node.id, |
| 635 | confidence: 0.6, |
| 636 | resolvedBy: 'framework', |
| 637 | metadata: { bridge: 'react-native', module: target.moduleName }, |
nothing calls this directly
no test coverage detected