MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / parseTurboModuleSpec

Function parseTurboModuleSpec

src/resolution/frameworks/react-native.ts:309–339  ·  view source on GitHub ↗

* Parse a TS file for a TurboModule spec declaration. The spec file is * the JS↔native source-of-truth in the new architecture — its interface * lists every JS-visible method, and a `TurboModuleRegistry.get* (...)` * default export pins the module name. * * Returns `null` when the file isn

(
  source: string
)

Source from the content-addressed store, hash-verified

307 * Returns `null` when the file isn't a TurboModule spec.
308 */
309function parseTurboModuleSpec(
310 source: string
311): { moduleName: string; methods: string[] } | null {
312 // `TurboModuleRegistry.getEnforcing<Spec>('ModuleName')` or
313 // `TurboModuleRegistry.get<Spec>('ModuleName')`. The literal must be a
314 // single-or-double-quoted string.
315 const regMatch = source.match(
316 /TurboModuleRegistry\.(?:getEnforcing|get)\s*<[^>]*>\s*\(\s*['"]([^'"]+)['"]\s*\)/
317 );
318 if (!regMatch || !regMatch[1]) return null;
319 const moduleName = regMatch[1];
320
321 // Find `export interface Spec extends TurboModule { … }` and pull each
322 // method declaration's name. We don't need types — just names.
323 const ifaceMatch = source.match(
324 /export\s+interface\s+Spec\b[^{]*\{([\s\S]*?)\n\}/
325 );
326 if (!ifaceMatch || !ifaceMatch[1]) return null;
327 const body = ifaceMatch[1];
328
329 const methods: string[] = [];
330 // Method shape: `name(args): ReturnType;` or `name(): void;`. Skip
331 // properties (no parens before colon).
332 const methodRegex = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*\(/gm;
333 let m: RegExpExecArray | null;
334 while ((m = methodRegex.exec(body)) !== null) {
335 const name = m[1];
336 if (name) methods.push(name);
337 }
338 return { moduleName, methods };
339}
340
341// ─── Map building ───────────────────────────────────────────────────────────
342

Callers 1

buildRNMapsFunction · 0.85

Calls 2

pushMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected