Skip to content

vox-rn-codegen API Reference (generated)

Crate: vox-rn-codegen · Version: 0.6.0 · Target: Library (lib.rs)

React Native + Expo TypeScript codegen extracted from vox-codegen.

React Native + Expo lowering for the BuildTarget::Mobile target.

This crate is one of two lowerings for Vox components. The web lowering (under vox_codegen::codegen_ts::reactive + component) consumes the same HirModule and produces React DOM + Tailwind output; this crate consumes the same HirModule and produces React Native + StyleSheet output. The HIR is the shared source of truth — there is no separate “RN HIR”.

Future split-brain protection: the vox-cli-tests harness asserts that for every Vox source under test, BOTH lowerings produce output that tsc --noEmit accepts. Any divergence in supported VUV vocabulary fails CI.

For a Vox module, [generate_rn] produces a self-contained set of files:

  • App.tsx — Expo Router root layout (when components are present).
  • <Component>.tsx — one file per component Name() { ... }. RN-flavored.
  • vox-client.ts — reused unchanged from the existing emit; HTTP layer is identical between web and mobile.
  • mobile.ts — reused unchanged (adapter contract via target="rn").
  • vox-app-contract.json, openapi.json, schemas.ts, types.ts — reused.
  • app.json, babel.config.js, metro.config.js, eas.json — Expo scaffold artifacts (one-shot, not overwritten).

What’s NOT yet emitted (will produce a clear codegen diagnostic, not silent stub)

Section titled “What’s NOT yet emitted (will produce a clear codegen diagnostic, not silent stub)”
  • @routes → expo-router file tree (see follow-on in Phase 1A.4).
  • Boolean @form fields → <Switch> (currently emits a TODO marker; users can hand-edit until the upstream HIR exposes switch metadata).
  • State machines are emitted unchanged (TypeScript-only; no React DOM coupling).
DependencyKind
vox-codegenNormal
vox-compilerNormal
vox-codegenDevelopment
vox-compilerDevelopment
ModuleDescription
component—
form—
mobile_utils—
routes—
scaffold—
StructDescription
RnCodegenOutputOutput of the RN lowering. Same shape as the web emitter’s CodegenOutput for symmetry.
FunctionDescription
generate_rnGenerate React Native + Expo TypeScript files from a Vox module. The caller is responsible for writing files. Returns Err on hard failures (e.g. unsupported features); use the diagnostics field for non-fatal warnings.
Dependency Topology, diagram 14 nodes, 3 edges: vox-rn-codegen → vox-codegen; vox-rn-codegen → vox-compiler; vox-cli → vox-rn-codegenvox-rn-codegenvox-codegenvox-compilervox-cli
Diagram source
graph {
direction: right
node vox_rn_codegen: "vox-rn-codegen"
node vox_codegen: "vox-codegen"
vox_rn_codegen -> vox_codegen
node vox_compiler: "vox-compiler"
vox_rn_codegen -> vox_compiler
node vox_cli: "vox-cli"
vox_cli -> vox_rn_codegen
}
Consumer CrateRole
vox-cliDirect workspace dependent
KindSymbolSignatureSourceDescription
structRnCodegenOutputpub struct RnCodegenOutputcrates/vox-rn-codegen/src/lib.rs#L43-L48Output of the RN lowering. Same shape as the web emitter’s CodegenOutput for symmetry.
fngenerate_rnpub fn generate_rn(hir: &HirModule, options: &CodegenOptions) -> Result<RnCodegenOutput, String>crates/vox-rn-codegen/src/lib.rs#L54Generate React Native + Expo TypeScript files from a Vox module. The caller is responsible for writing files. Returns Err on hard failures (e.g. unsupported features); use the diagnostics field for non-fatal warnings.
fncomponent::emit_rn_componentpub fn emit_rn_component(crates/vox-rn-codegen/src/component.rs#L1609Emit a single component file. known_components is the set of all component names in the module and endpoint_params maps each @query/@mutation/@server fn name to its ordered parameter names. The keys drive cross-file import statements (sibling components from ./Name, endpoint fns from ./vox-client); the values drive the positional→named-object rewrite for endpoint calls inside handlers. Both mirror the web reactive emit exactly, so the two targets stay in lockstep on what a component pulls in and how it calls endpoints.
fnform::emit_formpub fn emit_form(form: &HirForm) -> Stringcrates/vox-rn-codegen/src/form.rs#L21Emit a single @form as an RN function component string.
fnform::form_renders_switchpub fn form_renders_switch(form: &HirForm) -> boolcrates/vox-rn-codegen/src/form.rs#L236-L241True if any visible (non-hidden) field of form is a boolean — i.e. the emitted forms.tsx will render a <Switch> and therefore needs it imported.
fnmobile_utils::any_component_uses_mobilepub fn any_component_uses_mobile(hir: &HirModule) -> boolcrates/vox-rn-codegen/src/mobile_utils.rs#L24-L26Walk every component’s view, prelude, derived expressions, and effects to see if the bare identifier mobile appears anywhere. Used to decide whether mobile-utils.ts is needed and to know which component files should import { mobile } from "./mobile-utils".
fnmobile_utils::component_uses_mobilepub fn component_uses_mobile(rc: &vox_compiler::hir::HirReactiveComponent) -> boolcrates/vox-rn-codegen/src/mobile_utils.rs#L29-L71Check a single component for any reference to the mobile identifier.
fnmobile_utils::emit_mobile_utils_rnpub fn emit_mobile_utils_rn() -> Stringcrates/vox-rn-codegen/src/mobile_utils.rs#L140-L165Emit mobile-utils.ts content for the RN target. Re-exports a mobile namespace whose method names match the snake_case Vox source convention, each method delegating to @vox/runtime-rn.
fnroutes::emit_expo_router_filespub fn emit_expo_router_files(routes: &[RoutesDecl]) -> Vec<(String, String)>crates/vox-rn-codegen/src/routes.rs#L29-L46Emit every app/-prefixed route file plus the mandatory root _layout.tsx. Returns an empty Vec when there are no routes — the caller should fall back to emitting a flat App.tsx in that case.
fnscaffold::emit_expo_scaffoldpub fn emit_expo_scaffold(crates/vox-rn-codegen/src/scaffold.rs#L34Emit the Expo project skeleton. When has_routes is true the package.json main field points at expo-router/entry and the flat App.tsx is omitted (Expo Router uses file-system routing under app/); when false the legacy expo/AppEntry.js boot path is used with a generated App.tsx that mounts the first declared VUV component. app_name is the human-facing display name (vox build --app-name); the Expo slug / scheme / npm package name are its slugified form. app_id is the reverse-DNS identifier used for both the iOS bundle id and the Android package (vox build --app-id). Defaults: vox-app / com.vox.app.