/** * resolver-strip — build-mode pass that eliminates `zodResolver` from the * `@zod-to-form/react` `useZodForm` hook when the user has validation * optimization enabled (FR-013). * * The runtime hook keeps a static `import { zodResolver } from * '@hookform/resolvers/zod'` so non-optimized users get the resolver via * normal ESM evaluation. When optimization is on, every call site sits * inside an `isOptimized ? undefined : zodResolver(...)` ternary, and * the call is dead code — but Rollup's tree-shaker can't prove that * statically because the ternary's condition is a runtime value. * * This pure helper rewrites every `zodResolver(rhfCast(schema))` call * in `useZodForm` source to a literal `undefined`. After the rewrite * the import has zero remaining references, and Rollup eliminates the * import statement automatically — closing the gzipped delta the * benchmark page asserts. * * Pure: takes source + a "should-strip" flag, returns transformed source * + sourcemap. No I/O, no plugin context. The plugin's `transform` hook * decides WHEN to call it based on file id + config. */ import MagicString from 'magic-string'; export interface ResolverStripInput { /** The source code of the file (typically `useZodForm.{ts,js}`). */ source: string; } export interface ResolverStripOutput { /** Transformed code (or original if there was nothing to strip). */ code: string; /** Magic-string sourcemap (hires). */ map: ReturnType; /** Number of `zodResolver(...)` call sites the strip replaced. */ rewritten: number; } /** * Detect whether a Vite/Rollup module id refers to the `useZodForm` hook * source. We accept any extension (.ts / .tsx / .js / .mjs / .cjs) so * the strip works equally well in dev (raw .ts) and build (transpiled .js). */ export declare function isUseZodFormId(id: string): boolean; /** * Rewrite every `zodResolver(...)` call expression in `source` to * `undefined` AND remove the now-unused * `import { zodResolver } from '@hookform/resolvers/zod'` statement. * * Two-pass: first locate every call site (validates balanced parens * across the whole file), then apply edits via magic-string. If the * scan reports unbalanced parens we throw `Z2F_VITE_RESOLVER_STRIP_FAILED` * — partial rewrites would corrupt the file silently. * * Uses a regex sweep + manual paren balancing rather than an AST visitor * because the call shape in `useZodForm` is fixed and the strip is a * one-shot source-level rewrite — pulling Babel back in just for two * replacements would be massively over-engineered. */ export declare function stripResolver(input: ResolverStripInput): ResolverStripOutput; //# sourceMappingURL=resolver-strip.d.ts.map