(context: ResolutionContext)
| 361 | ]); |
| 362 | |
| 363 | function buildRNMaps(context: ResolutionContext): { byJsName: Map<string, NativeMethod[]>; aliases: Map<string, string> } { |
| 364 | const cached = nativeMethodMaps.get(context); |
| 365 | if (cached) return cached; |
| 366 | |
| 367 | const byJsName = new Map<string, NativeMethod[]>(); |
| 368 | const aliases = new Map<string, string>(); |
| 369 | const ambiguousAliases = new Set<string>(); |
| 370 | const allFiles = context.getAllFiles(); |
| 371 | // Pre-index native methods by name for fast lookup when matching to |
| 372 | // their bridge exports. |
| 373 | const objcMethodsByFirstKw = new Map<string, Node[]>(); |
| 374 | const jvmMethodsByName = new Map<string, Node[]>(); |
| 375 | const swiftMethodsByName = new Map<string, Node[]>(); |
| 376 | for (const node of context.getNodesByKind('method')) { |
| 377 | if (node.language === 'objc') { |
| 378 | const firstKw = node.name.includes(':') ? node.name.split(':')[0] : node.name; |
| 379 | if (firstKw) { |
| 380 | const arr = objcMethodsByFirstKw.get(firstKw); |
| 381 | if (arr) arr.push(node); |
| 382 | else objcMethodsByFirstKw.set(firstKw, [node]); |
| 383 | } |
| 384 | } else if (node.language === 'java' || node.language === 'kotlin') { |
| 385 | const arr = jvmMethodsByName.get(node.name); |
| 386 | if (arr) arr.push(node); |
| 387 | else jvmMethodsByName.set(node.name, [node]); |
| 388 | } else if (node.language === 'swift') { |
| 389 | const arr = swiftMethodsByName.get(node.name); |
| 390 | if (arr) arr.push(node); |
| 391 | else swiftMethodsByName.set(node.name, [node]); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | for (const file of allFiles) { |
| 396 | // Legacy bridge — ObjC side. |
| 397 | if (file.endsWith('.m') || file.endsWith('.mm')) { |
| 398 | const source = context.readFile(file); |
| 399 | if (!source) continue; |
| 400 | const className = findObjcClassName(source); |
| 401 | const exports = parseObjcRNExports(source, className); |
| 402 | for (const exp of exports) { |
| 403 | if (RN_EMITTER_BUILTINS.has(exp.jsName)) continue; |
| 404 | // Resolve to the native node by selector first-keyword. Multiple |
| 405 | // ObjC methods may share a first keyword across modules; filter by |
| 406 | // file path to attribute the export to this module's |
| 407 | // implementation file. |
| 408 | const candidates = objcMethodsByFirstKw.get(exp.nativeSelectorFirstKw) ?? []; |
| 409 | const node = candidates.find((c) => c.filePath === file) ?? candidates[0]; |
| 410 | if (!node) continue; |
| 411 | const entry: NativeMethod = { moduleName: exp.moduleName, jsName: exp.jsName, node }; |
| 412 | const arr = byJsName.get(exp.jsName); |
| 413 | if (arr) arr.push(entry); |
| 414 | else byJsName.set(exp.jsName, [entry]); |
| 415 | } |
| 416 | // Swift-backed module: the shim names the class; the implementation is |
| 417 | // the Swift method of that name on the class or one of its extensions. |
| 418 | // Class-scoped, so a same-named method on another Swift type (a |
| 419 | // `syncSettings` on `CaptureSettings` beside the one on `CaptureView`) |
| 420 | // is never the answer. |
no test coverage detected