混合 iOS / React Native / Expo 橋接

呼叫路徑跨語言邊界——不再是「Swift↔ObjC 斷在 static parsing」
8 種邊界 · 全部標註 provenance:'heuristic' + synthesizedBy channel

問題

真實的 iOS / React Native codebase 橫跨多種語言——Swift caller 呼叫被自動橋接的 Objective-C selector、JS 檔經由 RN bridge 呼叫 native module、JSX component 委派給 native view manager。純 tree-sitter 抽取在每個語言邊界就斷了。CodeGraph 把它們接起來,讓 codegraph_explore 端到端連通這些流——call path 與 blast radius 跨過邊界,而不是停在邊界。

8 種邊界

邊界JS / Swift 側Native 側做法
Swift → ObjCSwift obj.foo(bar:)ObjC selector -fooWithBar:@objc auto-bridging 規則(含 init/property/protocol 形式)+ Cocoa preposition 前綴(With/For/By/In/On/At…)
ObjC → SwiftObjC [obj fooWithBar:]Swift @objc func foo(bar:)Reverse-bridge 名稱候選;從原始碼驗證 @objc 暴露
RN legacy bridgeJS NativeModules.X.fn(...)ObjC RCT_EXPORT_METHOD/RCT_REMAP_METHOD · Java/Kotlin @ReactMethod解析 macro/annotation 宣告,建 JS-name → native-method map
RN TurboModulesJS import M from './NativeM'; M.fn(...)符合 Codegen spec 的 native implNative<X>.ts spec interface 當 ground truth
RN native → JS eventsJS new NativeEventEmitter(...).addListener('e', cb)ObjC [self sendEventWithName:@"e" body:...] · Swift sendEvent(withName: "e", ...) · Java/Kotlin .emit("e", ...)依字面 event name 合成跨語言事件通道
Expo ModulesJS requireNativeModule('X').fn(...)Swift / Kotlin Module { Name("X"); AsyncFunction("fn") { ... } }解析 Expo DSL 字面值;synthetic method 節點用既有 name-match 解析
Fabric view componentsJSX <MyView prop={v}/>TS Codegen spec + native impl classSpec → component 節點;慣例名稱+suffix(View/ComponentView/Manager/ViewManager)橋到 native
Legacy Paper view managersJSX <MyView prop={v}/>ObjC RCT_EXPORT_VIEW_PROPERTY · Java/Kotlin @ReactProp與 Fabric 相同——Paper 時代宣告也產 component + property 節點

可追溯性

每個 bridge 產出的邊都標 provenance:'heuristic',且 metadata.synthesizedBy: 設為穩定 channel 名(如 swift-objc-bridgern-event-channelfabric-native-implexpo-module-extract)——agent 一眼就能看出某個 hop 是怎麼進圖的。

已在真實 codebase 驗證

BridgeSmallMediumLarge
Swift ↔ ObjCChartsrealm-swiftWikipedia-iOS
RN legacy bridgeAsyncStoragereact-native-svgreact-native-firebase
RN native → JS eventsRNGeolocationreact-native-firebase
Expo Modulesexpo-hapticsexpo-cameraexpo SDK sweep(7 packages)
Fabric / Paper viewsreact-native-segmented-controlreact-native-screensreact-native-skia
看完這頁你應該能說出:為什麼 tree-sitter 在語言邊界斷流、Swift↔ObjC 與 RN bridge 各自靠什麼規則跨界、以及 synthesizedBy channel 對「agent 判斷 hop 可信度」的價值。