feat(resolution): mixed iOS / React Native / Expo cross-language bridging (#430)
Implements the design from `docs/design/mixed-ios-and-react-native-bridging.md`.
Closes the cross-language flow gap so `trace` / `callers` / `callees` / `impact` connect end-to-end across language boundaries in real iOS, React Native, and Expo codebases.
## Bridges shipped
| Boundary | Mechanism | Real-codebase validation |
|---|---|---|
| **Swift ↔ Objective-C** | Resolver applying Apple's @objc auto-bridging name math + Cocoa preposition prefixes | Charts (S, 269) · realm-swift (M, 369) · wikipedia-ios (L, 1734) |
| **React Native legacy bridge** | Resolver parsing `RCT_EXPORT_MODULE` / `RCT_EXPORT_METHOD` / `RCT_REMAP_METHOD` (ObjC) + `@ReactMethod` (Java/Kotlin) | AsyncStorage (S, ~60) · react-native-svg (M, ~700) · react-native-firebase (L, ~1100) |
| **React Native TurboModules** | Resolver treating `Native<X>.ts` spec interface as ground truth | via RNSvg + RNFirebase subsets |
| **Native → JS events** | Synthesizer matching native `sendEventWithName:`/`emit(...)` to JS `addListener('e', handler)` keyed by literal event name; falls back to enclosing constant/variable for wrapper-API parameter handlers | RNGeolocation (S) · RNFirebase (L) |
| **Expo Modules** | Framework extract synthesizes `method` nodes from Swift/Kotlin `Module { Name("X"); Function("y") { ... } }` DSL | expo-haptics (S, 14) · expo-camera (M, 72) · ExpoSweep (L, 332, 7 packages) |
| **Fabric + legacy Paper view components** | Extract `component` + `property` nodes from Codegen `codegenNativeComponent<Props>('Name', ...)` specs AND legacy `RCT_EXPORT_VIEW_PROPERTY` / `@ReactProp` macros, then synthesize component → native class by name+suffix convention | react-native-segmented-control (S, legacy) · react-native-screens (M, Codegen) · react-native-skia (L, hybrid monorepo) |
## Bug fixes surfaced along the way
- `tree-sitter.ts` message_expression — multi-keyword ObjC call sites now reconstruct `a🅱️` selectors so they resolve to multi-part method definitions (gap discovered post-#165; 0 → 84 call edges to `GET:parameters:...` style methods on AFNetworking).
- `src/index.ts` resolver lifecycle — `indexAll()` now re-initializes the resolver after extraction so framework `detect()` sees the populated index. Pre-existing latent bug that affected UIKit and SwiftUI resolvers too.
- `src/extraction/index.ts` `buildDetectionContext` — added `listDirectories` so framework detect() can probe monorepo subpackages uniformly (fix needed for react-native-skia detection).
## Regression check on 5 control repos
| Repo | Result |
|---|---|
| Express (small JS) | ✅ unchanged — 266 routes, express framework detected |
| Excalidraw (medium TS/React) | ✅ 9284 nodes (CLAUDE.md baseline ~9290); canonical `trace(mutateElement, renderStaticScene)` returns the flow |
| Django realworld (Python) | ✅ django framework detected, 16 routes |
| Spring petclinic (Java) | ✅ spring framework detected, 17 routes |
| Texture (pure ObjC, large) | ✅ exactly matches #165 baseline: 4702 methods, 894 classes, 808/808 file coverage, 913 multi-keyword selectors, 55 protocols, 1036 properties |
## Tests
928 passing (+87 net new bridge tests across the 5 channels); 2 pre-existing skips. The mcp-staleness-banner / watcher parallel flakiness is unchanged by this work (different test fails each run, all pass in isolation; pre-existing on main).
## Documentation
- README: new 'Mixed iOS / React Native / Expo bridging' section with the per-boundary table and validation-corpus links.
- CHANGELOG `[Unreleased]`: full entry per bridge with measurements.
- `docs/design/mixed-ios-and-react-native-bridging.md`: the design doc (§8 measurements filled in across §8a-§8g).
- `docs/design/dynamic-dispatch-coverage-playbook.md` §6 coverage matrix: six new rows.
- `.claude/skills/agent-eval/corpus.json`: four new sections covering 15 real GitHub repos for the eval harness.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import * as os from 'node:os';
|
||||
import { CodeGraph } from '../src';
|
||||
|
||||
/**
|
||||
* End-to-end synthesizer test: write a fixture project with a native ObjC
|
||||
* `sendEventWithName:` site and a JS `addListener('x', fn)` subscriber,
|
||||
* index it, and verify the synthesized cross-language event edge.
|
||||
*/
|
||||
describe('RN event channel synthesizer', () => {
|
||||
let dir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'rn-event-fixture-'));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it('synthesizes an edge from ObjC sendEventWithName: to JS addListener handler', async () => {
|
||||
// package.json so the RN detector / general resolver sees the project as RN.
|
||||
fs.writeFileSync(
|
||||
path.join(dir, 'package.json'),
|
||||
'{"name":"x","dependencies":{"react-native":"^0.73"}}'
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(dir, 'Emitter.m'),
|
||||
`
|
||||
@implementation Emitter
|
||||
- (void)reportLocation {
|
||||
[self sendEventWithName:@"locationUpdate" body:@{}];
|
||||
}
|
||||
@end
|
||||
`
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(dir, 'App.js'),
|
||||
`
|
||||
function onLocation(payload) {
|
||||
console.log(payload);
|
||||
}
|
||||
emitter.addListener('locationUpdate', onLocation);
|
||||
`
|
||||
);
|
||||
|
||||
const cg = await CodeGraph.init(dir, { silent: true });
|
||||
await cg.indexAll();
|
||||
|
||||
const db = (cg as any).db.db;
|
||||
const rows = db
|
||||
.prepare(
|
||||
`SELECT s.name source_name, s.language sl, t.name target_name, t.language tl,
|
||||
json_extract(e.metadata,'$.event') event
|
||||
FROM edges e
|
||||
JOIN nodes s ON s.id = e.source
|
||||
JOIN nodes t ON t.id = e.target
|
||||
WHERE json_extract(e.metadata,'$.synthesizedBy') = 'rn-event-channel'`
|
||||
)
|
||||
.all();
|
||||
cg.close?.();
|
||||
expect(rows.length).toBeGreaterThanOrEqual(1);
|
||||
// The edge should point from the ObjC method that emits to the JS handler.
|
||||
const edge = rows.find((r: any) => r.event === 'locationUpdate');
|
||||
expect(edge).toBeDefined();
|
||||
expect(edge.sl).toBe('objc');
|
||||
expect(edge.tl).toBe('javascript');
|
||||
expect(edge.target_name).toBe('onLocation');
|
||||
});
|
||||
|
||||
it('falls back to enclosing JS function when addListener handler is a parameter (wrapper-API pattern)', async () => {
|
||||
// Matches the real RNFirebase shape: `messaging().onMessage(listener)`
|
||||
// is a subscribe-wrapper whose body does
|
||||
// `addListener('messaging_message_received', listener)` where `listener`
|
||||
// is the parameter — not a globally-named symbol. Synthesizer should
|
||||
// still produce an edge, attributed to the enclosing wrapper function.
|
||||
fs.writeFileSync(
|
||||
path.join(dir, 'package.json'),
|
||||
'{"dependencies":{"react-native":"^0.73"}}'
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(dir, 'Native.m'),
|
||||
`
|
||||
@implementation MyEmitter
|
||||
- (void)pushMessage {
|
||||
[[Shared shared] sendEventWithName:@"messaging_message_received" body:@{}];
|
||||
}
|
||||
@end
|
||||
`
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(dir, 'messaging.ts'),
|
||||
`
|
||||
import { NativeEventEmitter } from 'react-native';
|
||||
const emitter = new NativeEventEmitter();
|
||||
export function onMessage(listener: (m: any) => void) {
|
||||
return emitter.addListener('messaging_message_received', listener);
|
||||
}
|
||||
`
|
||||
);
|
||||
|
||||
const cg = await CodeGraph.init(dir, { silent: true });
|
||||
await cg.indexAll();
|
||||
|
||||
const db = (cg as any).db.db;
|
||||
const rows = db
|
||||
.prepare(
|
||||
`SELECT s.name source_name, t.name target_name, t.kind target_kind, t.language tl,
|
||||
json_extract(e.metadata,'$.event') event
|
||||
FROM edges e
|
||||
JOIN nodes s ON s.id = e.source
|
||||
JOIN nodes t ON t.id = e.target
|
||||
WHERE json_extract(e.metadata,'$.synthesizedBy') = 'rn-event-channel'`
|
||||
)
|
||||
.all();
|
||||
cg.close?.();
|
||||
const edge = rows.find((r: any) => r.event === 'messaging_message_received');
|
||||
expect(edge).toBeDefined();
|
||||
// Target should be the wrapper function `onMessage` — the enclosing
|
||||
// function of the addListener call, not a bareword named handler.
|
||||
expect(edge.target_name).toBe('onMessage');
|
||||
expect(['function', 'method']).toContain(edge.target_kind);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user