zod-compiler 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +5 -0
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/core/codegen/build-path.js +18 -6
- package/dist/core/codegen/build-path.js.map +1 -1
- package/dist/core/codegen/context.d.ts +10 -1
- package/dist/core/codegen/context.d.ts.map +1 -1
- package/dist/core/codegen/context.js +15 -1
- package/dist/core/codegen/context.js.map +1 -1
- package/dist/core/codegen/issue-decls.d.ts +67 -5
- package/dist/core/codegen/issue-decls.d.ts.map +1 -1
- package/dist/core/codegen/issue-decls.js +72 -7
- package/dist/core/codegen/issue-decls.js.map +1 -1
- package/dist/core/codegen/schemas/array.d.ts.map +1 -1
- package/dist/core/codegen/schemas/array.js +3 -3
- package/dist/core/codegen/schemas/array.js.map +1 -1
- package/dist/core/codegen/schemas/effect.d.ts +13 -1
- package/dist/core/codegen/schemas/effect.d.ts.map +1 -1
- package/dist/core/codegen/schemas/effect.js +26 -3
- package/dist/core/codegen/schemas/effect.js.map +1 -1
- package/dist/core/codegen/schemas/fallback.d.ts +17 -1
- package/dist/core/codegen/schemas/fallback.d.ts.map +1 -1
- package/dist/core/codegen/schemas/fallback.js +31 -15
- package/dist/core/codegen/schemas/fallback.js.map +1 -1
- package/dist/core/codegen/schemas/number.d.ts.map +1 -1
- package/dist/core/codegen/schemas/number.js +35 -35
- package/dist/core/codegen/schemas/number.js.map +1 -1
- package/dist/core/codegen/schemas/object.d.ts.map +1 -1
- package/dist/core/codegen/schemas/object.js +64 -29
- package/dist/core/codegen/schemas/object.js.map +1 -1
- package/dist/core/codegen/schemas/string.d.ts.map +1 -1
- package/dist/core/codegen/schemas/string.js +3 -3
- package/dist/core/codegen/schemas/string.js.map +1 -1
- package/dist/core/codegen/schemas/template-literal.d.ts.map +1 -1
- package/dist/core/codegen/schemas/template-literal.js +1 -1
- package/dist/core/codegen/schemas/template-literal.js.map +1 -1
- package/dist/core/extract/index.d.ts.map +1 -1
- package/dist/core/extract/index.js +2 -0
- package/dist/core/extract/index.js.map +1 -1
- package/dist/core/extract/zod-version.d.ts +78 -0
- package/dist/core/extract/zod-version.d.ts.map +1 -0
- package/dist/core/extract/zod-version.js +109 -0
- package/dist/core/extract/zod-version.js.map +1 -0
- package/dist/jit.d.ts.map +1 -1
- package/dist/jit.js +9 -1
- package/dist/jit.js.map +1 -1
- package/dist/runtime.d.ts +3 -0
- package/dist/runtime.js +4 -1
- package/dist/unplugin/hoist-compile.d.ts.map +1 -1
- package/dist/unplugin/hoist-compile.js +3 -1
- package/dist/unplugin/hoist-compile.js.map +1 -1
- package/dist/unplugin/transform.d.ts.map +1 -1
- package/dist/unplugin/transform.js +5 -0
- package/dist/unplugin/transform.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,9 @@ input. No code changes required.
|
|
|
7
7
|
|
|
8
8
|
Requires **Zod ≥ 4.5**. Compiled output reproduces 4.5's semantics exactly, down to code-point string
|
|
9
9
|
lengths, symbol-keyed shapes and tuple issue order, so it does not match earlier 4.x releases. Stay on
|
|
10
|
-
zod-compiler 1.x for Zod 4.0–4.4.
|
|
10
|
+
zod-compiler 1.x for Zod 4.0–4.4. An older Zod is refused with an explicit error (the build plugin
|
|
11
|
+
and `jit()` warn once and leave the schemas as plain Zod) rather than compiled into validators that
|
|
12
|
+
disagree with it.
|
|
11
13
|
|
|
12
14
|
- [What Gets Compiled](#what-gets-compiled)
|
|
13
15
|
- [Schema Hoisting](#schema-hoisting)
|
|
@@ -577,11 +579,11 @@ not the whole object. Run `zod-compiler check` to see what compiled.
|
|
|
577
579
|
Compiled validators match Zod on verdicts, output data and error messages, including issue ordering.
|
|
578
580
|
Three things differ by design:
|
|
579
581
|
|
|
580
|
-
| Behavior | Zod | zod-compiler
|
|
581
|
-
| ------------------------- | ----------------------------------------------- |
|
|
582
|
-
| Record key iteration | Own enumerable keys, symbols included | Own enumerable **string** keys only
|
|
583
|
-
| Container output identity | A fresh array / set / map / object | The input container, by reference (array holes survive) |
|
|
584
|
-
| Per-call parse params | `safeParse(x, { error, reportInput })` honoured | Ignored; global `z.config()` maps still apply
|
|
582
|
+
| Behavior | Zod | zod-compiler |
|
|
583
|
+
| ------------------------- | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
584
|
+
| Record key iteration | Own enumerable keys, symbols included | Own enumerable **string** keys only |
|
|
585
|
+
| Container output identity | A fresh array / set / map / object | The input container, by reference (array holes and the input's key order survive); a rebuilt object is fresh and in zod's key order |
|
|
586
|
+
| Per-call parse params | `safeParse(x, { error, reportInput })` honoured | Ignored; global `z.config()` maps still apply |
|
|
585
587
|
|
|
586
588
|
Schema-level `error` and `z.config()` maps are unaffected; for a per-call map use
|
|
587
589
|
`z.safeParse(Schema, x, params)`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.ts","names":[],"sources":["../../../src/cli/commands/check.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"check.d.ts","names":[],"sources":["../../../src/cli/commands/check.ts"],"mappings":";UAmFiB;EACf;EACA;EACA;EACA;EACA;;iBAGoB,SAAS,SAAS,eAAe"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { discoverSchemas } from "../../discovery.js";
|
|
2
|
+
import { isUnsupportedZodVersionError } from "../../core/extract/zod-version.js";
|
|
2
3
|
import { extractSchema } from "../../core/extract/index.js";
|
|
3
4
|
import { getErrorMessage } from "../errors.js";
|
|
4
5
|
import { createColors, logger } from "../logger.js";
|
|
@@ -86,6 +87,10 @@ async function runCheck(options) {
|
|
|
86
87
|
try {
|
|
87
88
|
ir = extractSchema(s.schema, []);
|
|
88
89
|
} catch (e) {
|
|
90
|
+
if (isUnsupportedZodVersionError(e)) {
|
|
91
|
+
logger.error(getErrorMessage(e));
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
89
94
|
err(`${c.red}error${c.reset} Failed to extract "${s.exportName}" in ${relPath}: ${getErrorMessage(e)}`);
|
|
90
95
|
continue;
|
|
91
96
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.js","names":[],"sources":["../../../src/cli/commands/check.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport process from \"node:process\";\nimport type { DiagnosticNode, DiagnosticResult } from \"../../core/diagnostic.js\";\nimport { diagnoseSchema } from \"../../core/diagnostic.js\";\nimport type { RefEntry } from \"../../core/extract/index.js\";\nimport { extractSchema } from \"../../core/extract/index.js\";\nimport type { DiscoveredSchema, SchemaIR } from \"../../core/types.js\";\nimport { discoverSchemas } from \"../../discovery.js\";\nimport { getErrorMessage } from \"../errors.js\";\nimport type { Colors } from \"../logger.js\";\nimport { createColors, logger } from \"../logger.js\";\n\n// ─── Tree Rendering ─────────────────────────────────────────────────────────\n\nfunction renderTree(node: DiagnosticNode, c: Colors, prefix = \"\", isLast = true): string[] {\n const lines: string[] = [];\n const connector = prefix === \"\" ? \"\" : isLast ? \"└─ \" : \"├─ \";\n const childPrefix = prefix === \"\" ? \"\" : prefix + (isLast ? \" \" : \"│ \");\n\n const statusIcon = node.status === \"compiled\" ? `${c.green}✓${c.reset}` : `${c.red}✗${c.reset}`;\n const typeLabel = `${c.bold}${node.type}${c.reset}`;\n const pathLabel = node.path && node.path !== \"(root)\" ? ` ${c.dim}${node.path}${c.reset}` : \"\";\n const reasonLabel =\n node.status === \"fallback\" && node.reason ? ` ${c.yellow}(${node.reason})${c.reset}` : \"\";\n\n lines.push(`${prefix}${connector}${statusIcon} ${typeLabel}${pathLabel}${reasonLabel}`);\n\n if (node.status === \"fallback\" && node.hint) {\n const hintPrefix = `${childPrefix} `;\n lines.push(`${hintPrefix}${c.dim}hint: ${node.hint}${c.reset}`);\n }\n\n for (const [i, child] of node.children.entries()) {\n const last = i === node.children.length - 1;\n lines.push(...renderTree(child, c, childPrefix, last));\n }\n\n return lines;\n}\n\n// ─── JSON Output ────────────────────────────────────────────────────────────\n\ninterface JsonSchemaReport {\n exportName: string;\n coverage: { total: number; compilable: number; percent: number };\n fastPath: { eligible: boolean; blocker?: string };\n fallbacks: { reason: string; path: string; hint: string }[];\n}\n\ninterface JsonReport {\n file: string;\n schemas: JsonSchemaReport[];\n}\n\nfunction buildJsonReport(\n filePath: string,\n results: { exportName: string; diagnostic: DiagnosticResult }[],\n): JsonReport {\n return {\n file: filePath,\n schemas: results.map(({ exportName, diagnostic }) => {\n const report: JsonSchemaReport = {\n exportName,\n coverage: {\n total: diagnostic.total,\n compilable: diagnostic.compilable,\n percent: diagnostic.coveragePct,\n },\n fastPath: { eligible: diagnostic.fastPathEligible },\n fallbacks: diagnostic.fallbacks,\n };\n if (diagnostic.fastPathBlocker) {\n report.fastPath.blocker = diagnostic.fastPathBlocker;\n }\n return report;\n }),\n };\n}\n\n// ─── Command ────────────────────────────────────────────────────────────────\n\nexport interface CheckOptions {\n inputs: string[];\n json: boolean;\n failUnder: number | undefined;\n noColor: boolean;\n autoDiscover: boolean;\n}\n\nexport async function runCheck(options: CheckOptions): Promise<void> {\n // oxlint-disable-next-line no-console -- CLI output\n const out = console.log;\n // oxlint-disable-next-line no-console -- CLI output\n const err = console.error;\n const colorEnabled = !options.noColor && process.stdout.isTTY === true;\n const c = createColors(colorEnabled);\n const files: string[] = [];\n\n for (const input of options.inputs) {\n const absPath = path.resolve(input);\n const stat = await fs.promises.stat(absPath).catch(() => null);\n\n if (!stat) {\n logger.error(`File not found: ${input}`);\n process.exit(1);\n }\n\n if (stat.isDirectory()) {\n logger.error(\"check command expects file paths, not directories.\");\n process.exit(1);\n }\n\n files.push(absPath);\n }\n\n const allJsonReports: JsonReport[] = [];\n let minCoverage = 100;\n let schemasProcessed = 0;\n\n for (const filePath of files) {\n const relPath = path.relative(process.cwd(), filePath);\n\n let schemas: DiscoveredSchema[];\n try {\n schemas = await discoverSchemas(filePath, { autoDiscover: options.autoDiscover });\n } catch (e) {\n logger.error(`Failed to load ${relPath}: ${getErrorMessage(e)}`);\n process.exit(1);\n }\n\n if (schemas.length === 0) {\n const hint = options.autoDiscover\n ? \"no Zod schemas exported\"\n : \"no compile() calls found (use --schemas auto to scan plain Zod exports)\";\n logger.warn(`${relPath}: ${hint}`);\n continue;\n }\n\n const results: { exportName: string; diagnostic: DiagnosticResult }[] = [];\n\n for (const s of schemas) {\n let ir: SchemaIR;\n try {\n // Collect refs exactly as the compile pipeline does. A callback that\n // captures is compiled by REFERENCE through an `__rf[]` entry, which\n // only happens when a ref table is present — extracting without one\n // reports every captured refine/transform and every superRefine as a\n // fallback, so `check` claimed 0% on schemas `generate` compiles in\n // full and told the user to rewrite code that was already fast.\n const refEntries: RefEntry[] = [];\n ir = extractSchema(s.schema, refEntries);\n } catch (e) {\n err(\n `${c.red}error${c.reset} Failed to extract \"${s.exportName}\" in ${relPath}: ${getErrorMessage(e)}`,\n );\n continue;\n }\n const diagnostic = diagnoseSchema(ir);\n results.push({ exportName: s.exportName, diagnostic });\n schemasProcessed++;\n\n if (diagnostic.coveragePct < minCoverage) {\n minCoverage = diagnostic.coveragePct;\n }\n }\n\n if (options.json) {\n allJsonReports.push(buildJsonReport(relPath, results));\n } else {\n out(`\\n${c.bold}${relPath}${c.reset}`);\n\n for (const { exportName, diagnostic } of results) {\n const pctColor = diagnostic.coveragePct === 100 ? c.green : c.yellow;\n const fpLabel = diagnostic.fastPathEligible\n ? `${c.green}Fast Path: eligible${c.reset}`\n : `${c.yellow}Fast Path: ineligible${c.reset}${c.dim} (${diagnostic.fastPathBlocker})${c.reset}`;\n\n out(\n `\\n ${c.cyan}${exportName}${c.reset} — ${pctColor}${diagnostic.coveragePct}%${c.reset} compiled (${diagnostic.compilable}/${diagnostic.total} nodes) | ${fpLabel}`,\n );\n\n const treeLines = renderTree(diagnostic.root, c, \" \");\n for (const line of treeLines) {\n out(line);\n }\n\n if (diagnostic.fallbacks.length > 0) {\n out(`\\n ${c.yellow}Fallbacks:${c.reset}`);\n for (const fb of diagnostic.fallbacks) {\n out(` ${c.red}✗${c.reset} ${fb.path} — ${fb.reason}`);\n out(` ${c.dim}${fb.hint}${c.reset}`);\n }\n }\n }\n }\n }\n\n if (options.json) {\n out(JSON.stringify(allJsonReports, null, 2));\n }\n\n if (options.failUnder !== undefined) {\n if (schemasProcessed === 0) {\n logger.error(\"No schemas were analyzed — cannot satisfy --fail-under\");\n process.exit(1);\n }\n if (minCoverage < options.failUnder) {\n logger.error(`Coverage ${minCoverage}% is below threshold ${options.failUnder}%`);\n process.exit(1);\n }\n } else if (schemasProcessed === 0) {\n process.exit(1);\n }\n}\n"],"mappings":";;;;;;;;;AAeA,SAAS,WAAW,MAAsB,GAAW,SAAS,IAAI,SAAS,MAAgB;CACzF,MAAM,QAAkB,CAAC;CACzB,MAAM,YAAY,WAAW,KAAK,KAAK,SAAS,QAAQ;CACxD,MAAM,cAAc,WAAW,KAAK,KAAK,UAAU,SAAS,QAAQ;CAEpE,MAAM,aAAa,KAAK,WAAW,aAAa,GAAG,EAAE,MAAM,GAAG,EAAE,UAAU,GAAG,EAAE,IAAI,GAAG,EAAE;CACxF,MAAM,YAAY,GAAG,EAAE,OAAO,KAAK,OAAO,EAAE;CAC5C,MAAM,YAAY,KAAK,QAAQ,KAAK,SAAS,WAAW,IAAI,EAAE,MAAM,KAAK,OAAO,EAAE,UAAU;CAC5F,MAAM,cACJ,KAAK,WAAW,cAAc,KAAK,SAAS,IAAI,EAAE,OAAO,GAAG,KAAK,OAAO,GAAG,EAAE,UAAU;CAEzF,MAAM,KAAK,GAAG,SAAS,YAAY,WAAW,GAAG,YAAY,YAAY,aAAa;CAEtF,IAAI,KAAK,WAAW,cAAc,KAAK,MAAM;EAC3C,MAAM,aAAa,GAAG,YAAY;EAClC,MAAM,KAAK,GAAG,aAAa,EAAE,IAAI,QAAQ,KAAK,OAAO,EAAE,OAAO;CAChE;CAEA,KAAK,MAAM,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;IACvD,KAAK,MAAM,QAAQ,WACjB,IAAI,IAAI;IAGV,IAAI,WAAW,UAAU,SAAS,GAAG;KACnC,IAAI,SAAS,EAAE,OAAO,YAAY,EAAE,OAAO;KAC3C,KAAK,MAAM,MAAM,WAAW,WAAW;MACrC,IAAI,SAAS,EAAE,IAAI,GAAG,EAAE,MAAM,GAAG,GAAG,KAAK,KAAK,GAAG,QAAQ;MACzD,IAAI,WAAW,EAAE,MAAM,GAAG,OAAO,EAAE,OAAO;KAC5C;IACF;GACF;EACF;CACF;CAEA,IAAI,QAAQ,MACV,IAAI,KAAK,UAAU,gBAAgB,MAAM,CAAC,CAAC;CAG7C,IAAI,QAAQ,cAAc,KAAA,GAAW;EACnC,IAAI,qBAAqB,GAAG;GAC1B,OAAO,MAAM,wDAAwD;GACrE,QAAQ,KAAK,CAAC;EAChB;EACA,IAAI,cAAc,QAAQ,WAAW;GACnC,OAAO,MAAM,YAAY,YAAY,uBAAuB,QAAQ,UAAU,EAAE;GAChF,QAAQ,KAAK,CAAC;EAChB;CACF,OAAO,IAAI,qBAAqB,GAC9B,QAAQ,KAAK,CAAC;AAElB"}
|
|
1
|
+
{"version":3,"file":"check.js","names":[],"sources":["../../../src/cli/commands/check.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport process from \"node:process\";\nimport type { DiagnosticNode, DiagnosticResult } from \"../../core/diagnostic.js\";\nimport { diagnoseSchema } from \"../../core/diagnostic.js\";\nimport type { RefEntry } from \"../../core/extract/index.js\";\nimport { extractSchema } from \"../../core/extract/index.js\";\nimport { isUnsupportedZodVersionError } from \"../../core/extract/zod-version.js\";\nimport type { DiscoveredSchema, SchemaIR } from \"../../core/types.js\";\nimport { discoverSchemas } from \"../../discovery.js\";\nimport { getErrorMessage } from \"../errors.js\";\nimport type { Colors } from \"../logger.js\";\nimport { createColors, logger } from \"../logger.js\";\n\n// ─── Tree Rendering ─────────────────────────────────────────────────────────\n\nfunction renderTree(node: DiagnosticNode, c: Colors, prefix = \"\", isLast = true): string[] {\n const lines: string[] = [];\n const connector = prefix === \"\" ? \"\" : isLast ? \"└─ \" : \"├─ \";\n const childPrefix = prefix === \"\" ? \"\" : prefix + (isLast ? \" \" : \"│ \");\n\n const statusIcon = node.status === \"compiled\" ? `${c.green}✓${c.reset}` : `${c.red}✗${c.reset}`;\n const typeLabel = `${c.bold}${node.type}${c.reset}`;\n const pathLabel = node.path && node.path !== \"(root)\" ? ` ${c.dim}${node.path}${c.reset}` : \"\";\n const reasonLabel =\n node.status === \"fallback\" && node.reason ? ` ${c.yellow}(${node.reason})${c.reset}` : \"\";\n\n lines.push(`${prefix}${connector}${statusIcon} ${typeLabel}${pathLabel}${reasonLabel}`);\n\n if (node.status === \"fallback\" && node.hint) {\n const hintPrefix = `${childPrefix} `;\n lines.push(`${hintPrefix}${c.dim}hint: ${node.hint}${c.reset}`);\n }\n\n for (const [i, child] of node.children.entries()) {\n const last = i === node.children.length - 1;\n lines.push(...renderTree(child, c, childPrefix, last));\n }\n\n return lines;\n}\n\n// ─── JSON Output ────────────────────────────────────────────────────────────\n\ninterface JsonSchemaReport {\n exportName: string;\n coverage: { total: number; compilable: number; percent: number };\n fastPath: { eligible: boolean; blocker?: string };\n fallbacks: { reason: string; path: string; hint: string }[];\n}\n\ninterface JsonReport {\n file: string;\n schemas: JsonSchemaReport[];\n}\n\nfunction buildJsonReport(\n filePath: string,\n results: { exportName: string; diagnostic: DiagnosticResult }[],\n): JsonReport {\n return {\n file: filePath,\n schemas: results.map(({ exportName, diagnostic }) => {\n const report: JsonSchemaReport = {\n exportName,\n coverage: {\n total: diagnostic.total,\n compilable: diagnostic.compilable,\n percent: diagnostic.coveragePct,\n },\n fastPath: { eligible: diagnostic.fastPathEligible },\n fallbacks: diagnostic.fallbacks,\n };\n if (diagnostic.fastPathBlocker) {\n report.fastPath.blocker = diagnostic.fastPathBlocker;\n }\n return report;\n }),\n };\n}\n\n// ─── Command ────────────────────────────────────────────────────────────────\n\nexport interface CheckOptions {\n inputs: string[];\n json: boolean;\n failUnder: number | undefined;\n noColor: boolean;\n autoDiscover: boolean;\n}\n\nexport async function runCheck(options: CheckOptions): Promise<void> {\n // oxlint-disable-next-line no-console -- CLI output\n const out = console.log;\n // oxlint-disable-next-line no-console -- CLI output\n const err = console.error;\n const colorEnabled = !options.noColor && process.stdout.isTTY === true;\n const c = createColors(colorEnabled);\n const files: string[] = [];\n\n for (const input of options.inputs) {\n const absPath = path.resolve(input);\n const stat = await fs.promises.stat(absPath).catch(() => null);\n\n if (!stat) {\n logger.error(`File not found: ${input}`);\n process.exit(1);\n }\n\n if (stat.isDirectory()) {\n logger.error(\"check command expects file paths, not directories.\");\n process.exit(1);\n }\n\n files.push(absPath);\n }\n\n const allJsonReports: JsonReport[] = [];\n let minCoverage = 100;\n let schemasProcessed = 0;\n\n for (const filePath of files) {\n const relPath = path.relative(process.cwd(), filePath);\n\n let schemas: DiscoveredSchema[];\n try {\n schemas = await discoverSchemas(filePath, { autoDiscover: options.autoDiscover });\n } catch (e) {\n logger.error(`Failed to load ${relPath}: ${getErrorMessage(e)}`);\n process.exit(1);\n }\n\n if (schemas.length === 0) {\n const hint = options.autoDiscover\n ? \"no Zod schemas exported\"\n : \"no compile() calls found (use --schemas auto to scan plain Zod exports)\";\n logger.warn(`${relPath}: ${hint}`);\n continue;\n }\n\n const results: { exportName: string; diagnostic: DiagnosticResult }[] = [];\n\n for (const s of schemas) {\n let ir: SchemaIR;\n try {\n // Collect refs exactly as the compile pipeline does. A callback that\n // captures is compiled by REFERENCE through an `__rf[]` entry, which\n // only happens when a ref table is present — extracting without one\n // reports every captured refine/transform and every superRefine as a\n // fallback, so `check` claimed 0% on schemas `generate` compiles in\n // full and told the user to rewrite code that was already fast.\n const refEntries: RefEntry[] = [];\n ir = extractSchema(s.schema, refEntries);\n } catch (e) {\n // An unsupported zod fails every schema identically, and nothing after\n // it can compile: report it once and stop, rather than once per export\n // followed by a coverage table that says 0% everywhere.\n if (isUnsupportedZodVersionError(e)) {\n logger.error(getErrorMessage(e));\n process.exit(1);\n }\n err(\n `${c.red}error${c.reset} Failed to extract \"${s.exportName}\" in ${relPath}: ${getErrorMessage(e)}`,\n );\n continue;\n }\n const diagnostic = diagnoseSchema(ir);\n results.push({ exportName: s.exportName, diagnostic });\n schemasProcessed++;\n\n if (diagnostic.coveragePct < minCoverage) {\n minCoverage = diagnostic.coveragePct;\n }\n }\n\n if (options.json) {\n allJsonReports.push(buildJsonReport(relPath, results));\n } else {\n out(`\\n${c.bold}${relPath}${c.reset}`);\n\n for (const { exportName, diagnostic } of results) {\n const pctColor = diagnostic.coveragePct === 100 ? c.green : c.yellow;\n const fpLabel = diagnostic.fastPathEligible\n ? `${c.green}Fast Path: eligible${c.reset}`\n : `${c.yellow}Fast Path: ineligible${c.reset}${c.dim} (${diagnostic.fastPathBlocker})${c.reset}`;\n\n out(\n `\\n ${c.cyan}${exportName}${c.reset} — ${pctColor}${diagnostic.coveragePct}%${c.reset} compiled (${diagnostic.compilable}/${diagnostic.total} nodes) | ${fpLabel}`,\n );\n\n const treeLines = renderTree(diagnostic.root, c, \" \");\n for (const line of treeLines) {\n out(line);\n }\n\n if (diagnostic.fallbacks.length > 0) {\n out(`\\n ${c.yellow}Fallbacks:${c.reset}`);\n for (const fb of diagnostic.fallbacks) {\n out(` ${c.red}✗${c.reset} ${fb.path} — ${fb.reason}`);\n out(` ${c.dim}${fb.hint}${c.reset}`);\n }\n }\n }\n }\n }\n\n if (options.json) {\n out(JSON.stringify(allJsonReports, null, 2));\n }\n\n if (options.failUnder !== undefined) {\n if (schemasProcessed === 0) {\n logger.error(\"No schemas were analyzed — cannot satisfy --fail-under\");\n process.exit(1);\n }\n if (minCoverage < options.failUnder) {\n logger.error(`Coverage ${minCoverage}% is below threshold ${options.failUnder}%`);\n process.exit(1);\n }\n } else if (schemasProcessed === 0) {\n process.exit(1);\n }\n}\n"],"mappings":";;;;;;;;;;AAgBA,SAAS,WAAW,MAAsB,GAAW,SAAS,IAAI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AC,CAAC;CAG7C,IAAI,QAAQ,cAAc,KAAA,GAAW;EACnC,IAAI,qBAAqB,GAAG;GAC1B,OAAO,MAAM,wDAAwD;GACrE,QAAQ,KAAK,CAAC;EAChB;EACA,IAAI,cAAc,QAAQ,WAAW;GACnC,OAAO,MAAM,YAAY,YAAY,uBAAuB,QAAQ,UAAU,EAAE;GAChF,QAAQ,KAAK,CAAC;EAChB;CACF,OAAO,IAAI,qBAAqB,GAC9B,QAAQ,KAAK,CAAC;AAElB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { declareFastTemps, emitEffectCallable, emitEffectFn, emitPooledConstant, emitRuntimeHelper, emitTemp, escapeString, hasMutation, keyMembershipTest, literalToJs, needsProtoScrub, outputAlwaysDefined, rejectsUndefined, tupleRewritesShortInput } from "./context.js";
|
|
2
|
-
import { ZC_HOP_DECL, ZC_PLAIN_DECL, ZC_PROTO_SCRUB_DECL } from "./issue-decls.js";
|
|
2
|
+
import { ZC_ASYNC_DECL, ZC_HOP_DECL, ZC_PLAIN_DECL, ZC_PROTO_SCRUB_DECL } from "./issue-decls.js";
|
|
3
3
|
import { defaultValueExpr, needsPostInnerDefault } from "./schemas/default.js";
|
|
4
4
|
import { detectUnionDiscriminator } from "./schemas/discriminated-union.js";
|
|
5
5
|
import { estimateFastCost, orderByRuntimeCost, predictedInlineSize } from "./fast-size.js";
|
|
@@ -597,12 +597,23 @@ function buildObject(ir, input, g) {
|
|
|
597
597
|
appends += slot.always ? `${out}[${slot.keyStr}]=${slot.value};` : `if(${slot.value}!==undefined||(${slot.keyStr} in ${input})){${out}[${slot.keyStr}]=${slot.value};}`;
|
|
598
598
|
}
|
|
599
599
|
code += `${out}={${literal.join(",")}};${appends}`;
|
|
600
|
-
for (const check of refines) code +=
|
|
600
|
+
for (const check of refines) code += buildRefine(check, out, g);
|
|
601
601
|
return {
|
|
602
602
|
code,
|
|
603
603
|
value: out
|
|
604
604
|
};
|
|
605
605
|
}
|
|
606
|
+
/**
|
|
607
|
+
* A `.refine()` predicate on the build path: FAIL on a falsy verdict, and
|
|
608
|
+
* zod's synchronous-parse error on a Promise — which is truthy, so an
|
|
609
|
+
* unguarded test would accept the input (see ZC_ASYNC_DECL). The verdict is
|
|
610
|
+
* bound to a local so the Promise test reads it once.
|
|
611
|
+
*/
|
|
612
|
+
function buildRefine(check, value, g) {
|
|
613
|
+
const asy = emitRuntimeHelper(g.ctx, "__zcAsy", ZC_ASYNC_DECL);
|
|
614
|
+
const verdict = local(g, "br");
|
|
615
|
+
return `${verdict}=${emitEffectCallable(g.ctx, check)}(${value});if(${verdict} instanceof Promise)${asy}();if(!${verdict})return ${g.fail};`;
|
|
616
|
+
}
|
|
606
617
|
function buildArray(ir, input, g) {
|
|
607
618
|
let sizes = "";
|
|
608
619
|
const refines = [];
|
|
@@ -627,7 +638,7 @@ function buildArray(ir, input, g) {
|
|
|
627
638
|
const inner = build(ir.element, elem, g);
|
|
628
639
|
if (inner === null) return null;
|
|
629
640
|
let code = `if(!Array.isArray(${input}))return ${g.fail};` + sizes + `${out}=new Array(${input}.length);for(${index}=0;${index}<${input}.length;${index}++){${elem}=${input}[${index}];${inner.code}${out}[${index}]=${inner.value};}`;
|
|
630
|
-
for (const check of refines) code +=
|
|
641
|
+
for (const check of refines) code += buildRefine(check, out, g);
|
|
631
642
|
return {
|
|
632
643
|
code,
|
|
633
644
|
value: out
|
|
@@ -678,12 +689,13 @@ function buildRecord(ir, input, g) {
|
|
|
678
689
|
* (see extractPipe), so there is no parse context to reproduce.
|
|
679
690
|
*/
|
|
680
691
|
function buildEffect(ir, input, g) {
|
|
692
|
+
const asy = emitRuntimeHelper(g.ctx, "__zcAsy", ZC_ASYNC_DECL);
|
|
681
693
|
if (ir.effectKind === "preprocess") {
|
|
682
694
|
const value = local(g, "bpv");
|
|
683
695
|
const inner = build(ir.inner, value, g);
|
|
684
696
|
if (inner === null) return null;
|
|
685
697
|
return {
|
|
686
|
-
code: `${value}=${emitEffectCallable(g.ctx, ir)}(${input});${inner.code}`,
|
|
698
|
+
code: `${value}=${emitEffectCallable(g.ctx, ir)}(${input});if(${value} instanceof Promise)${asy}();${inner.code}`,
|
|
687
699
|
value: inner.value
|
|
688
700
|
};
|
|
689
701
|
}
|
|
@@ -691,7 +703,7 @@ function buildEffect(ir, input, g) {
|
|
|
691
703
|
if (inner === null) return null;
|
|
692
704
|
const out = local(g, "bx");
|
|
693
705
|
return {
|
|
694
|
-
code: `${inner.code}${out}=${emitEffectCallable(g.ctx, ir)}(${inner.value});`,
|
|
706
|
+
code: `${inner.code}${out}=${emitEffectCallable(g.ctx, ir)}(${inner.value});if(${out} instanceof Promise)${asy}();`,
|
|
695
707
|
value: out
|
|
696
708
|
};
|
|
697
709
|
}
|
|
@@ -715,7 +727,7 @@ function buildString(ir, input, g) {
|
|
|
715
727
|
code += `${value}=${emitEffectFn(g.ctx, check.source)}(${value});`;
|
|
716
728
|
break;
|
|
717
729
|
case "refine_effect":
|
|
718
|
-
code +=
|
|
730
|
+
code += buildRefine(check, value, g);
|
|
719
731
|
break;
|
|
720
732
|
case "super_refine_effect": return null;
|
|
721
733
|
default: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-path.js","names":[],"sources":["../../../src/core/codegen/build-path.ts"],"sourcesContent":["/**\n * Build Path: one uninstrumented pass that VALIDATES and BUILDS rewritten\n * output together, abandoning the whole parse at the first failing check.\n *\n * `z.object()` strips unknown keys, so a successful parse cannot return the\n * input by reference — it must produce a fresh object. That rules out the Fast\n * Path (whose contract is `data === input`), and before this the only remaining\n * option was the eager slow walk: a fully instrumented traversal that collects\n * issues on every parse, valid or not.\n *\n * Two passes are wasteful in either direction. Validating first and building\n * afterwards reads every property twice (measured 29.7 ns vs 21.6 for the slow\n * walk on a 6-field object). Building with issue collection pays the\n * instrumentation even when nothing fails. Doing both in ONE pass, with a\n * sentinel instead of an issues array, beats both — and a failure costs only\n * the checks up to the first bad one, because the issue-producing walk is\n * deferred into `.error` exactly as `__zcFinD` does for mutation-free schemas:\n *\n * object clean object invalid array(8) invalid\n * slow walk 21.6 ns 30.4 ns 197.5 ns\n * build path 18.1 ns 7.7 ns 9.8 ns\n *\n * A subtree that rebuilds nothing is validated with its existing Fast Path\n * expression and passed through by reference, so only nodes that genuinely\n * produce a new value need code here; anything else returns null and keeps the\n * eager walk.\n *\n * Coverage is what decides whether this pass is reached at all, because it is\n * all-or-nothing per schema: ONE unmodelled node anywhere in the tree costs the\n * whole schema its single-pass parse. Modelled, beyond the stripping containers\n * this started with: array size checks and `.refine()`, object-level `.refine()`,\n * `.default()` substitution, ordered string rewrites (`.trim()`,\n * `.toLowerCase()`), sync `.transform()`, `z.stringbool()`, and the five native\n * coercions (`string`, `number`, `boolean`, `bigint`, `date`). Still declined, via\n * {@link mutatesBeyondStrip} — `.catch()` (its callback wants the inner schema's\n * issue list, which this pass never builds), `z.url()`, and `superRefine`.\n */\n\nimport type {\n DiscriminatedUnionIR,\n ObjectIR,\n RefineEffectCheckIR,\n SchemaIR,\n StringBoolIR,\n} from \"../types.js\";\nimport type { CodeGenContext, FastScope } from \"./context.js\";\nimport {\n declareFastTemps,\n emitEffectCallable,\n emitEffectFn,\n emitPooledConstant,\n emitRuntimeHelper,\n emitTemp,\n escapeString,\n hasMutation,\n keyMembershipTest,\n literalToJs,\n needsProtoScrub,\n outputAlwaysDefined,\n rejectsUndefined,\n tupleRewritesShortInput,\n} from \"./context.js\";\nimport { createFastGen, generateFast } from \"./fast-path.js\";\nimport {\n EXTRACT_CAP,\n estimateFastCost,\n MIN_EXTRACT,\n orderByRuntimeCost,\n predictedInlineSize,\n} from \"./fast-size.js\";\nimport { ZC_HOP_DECL, ZC_PLAIN_DECL, ZC_PROTO_SCRUB_DECL } from \"./issue-decls.js\";\nimport { defaultValueExpr, needsPostInnerDefault } from \"./schemas/default.js\";\nimport { parsedProperties } from \"./schemas/object.js\";\nimport { innerAppliesDefaultOnUndefined } from \"./schemas/optional.js\";\nimport { detectUnionDiscriminator } from \"./schemas/discriminated-union.js\";\nimport { fastStringCheck } from \"./schemas/string.js\";\nimport {\n emitStringBoolMap,\n stringBoolInlineHit,\n stringBoolUsesInline,\n} from \"./schemas/string-bool.js\";\n\n/** Statements that leave the built value in `value`, or `return <FAIL>` on failure. */\ninterface Built {\n code: string;\n value: string;\n}\n\ninterface BuildGen {\n ctx: CodeGenContext;\n /** Identifier of the per-validator FAIL sentinel. */\n fail: string;\n /** `var` temps and running emitted size of the function being assembled. */\n scope: FastScope;\n /**\n * May THIS node be hosted in its own function? False for the node a hosted\n * build was created for — it already IS that function, so re-hosting it would\n * recurse forever. Children are always extractable, letting an oversized\n * helper split further.\n */\n extractable: boolean;\n /** Nodes of the root schema that rebuild (see rebuildSet). */\n rebuilds: ReadonlySet<SchemaIR>;\n /**\n * Set on the gen for a dispatched union option (see buildDispatch): the\n * discriminator key. The switch that selected the option has already proved\n * the input is an object and matched this key's value, so `buildObject`\n * emits neither check again. Consumed by the first object reached — directly\n * or through a transparent wrapper — and never inherited past it.\n */\n discSkipKey?: string | undefined;\n}\n\n/**\n * Which nodes of `root` produce a value that is not their input — a stripping\n * object, coercion, codec, default, overwrite or transform, including\n * containers that contain one. Everything else can be validated in place and\n * passed through, which is what keeps this generator small.\n *\n * Computed as a fixpoint rather than a plain walk because of recursion: a\n * `recursiveRef` is a back-edge with no children, so a local walk reads false\n * for it and would pass the whole recursive subtree through by reference —\n * leaving every nested value unstripped while the outermost one was rebuilt.\n * Resolving the ref against its target closes the cycle, and iterating to a\n * fixpoint settles the mutual dependency between the two.\n */\nfunction rebuildSet(root: SchemaIR, includeProtoScrub = true): ReadonlySet<SchemaIR> {\n const targets = new Map<number, SchemaIR>([[0, root]]);\n const nodes: SchemaIR[] = [];\n const seen = new Set<SchemaIR>();\n const collect = (node: SchemaIR): void => {\n if (seen.has(node)) return;\n seen.add(node);\n nodes.push(node);\n if (node.type === \"recursionTarget\") targets.set(node.refId, node.inner);\n for (const child of children(node)) collect(child);\n };\n collect(root);\n\n const rebuilds = new Set<SchemaIR>();\n for (let changed = true; changed;) {\n changed = false;\n for (const node of nodes) {\n if (rebuilds.has(node)) continue;\n const target = node.type === \"recursiveRef\" ? targets.get(node.refId ?? 0) : undefined;\n const rebuild =\n (node.type === \"object\" && node.stripUnknownKeys === true) ||\n // A freezing readonly's output is `Object.freeze(inner)` — a value the\n // caller never handed us, so it must be BUILT rather than passed\n // through. Marking it here is also what makes `rebuildsOutput` true and\n // so withholds every by-reference shortcut above it.\n (node.type === \"readonly\" && node.freeze === true) ||\n // `.default()` substitutes its own value for `undefined`, so its output\n // is not its input even when the inner schema passes through — it must\n // never be handed to `passthrough`, whose fast check would reject the\n // absent value outright.\n node.type === \"default\" ||\n // A tuple whose output can differ from a SHORT input it accepts —\n // `z.tuple([z.any()]).rest(z.number())` answers `[]` with `[undefined]`\n // — is not its own input either. `fastTuple` narrows exactly those\n // slots to \"present\" (sound for the root shortcut, which only reads a\n // TRUE result), so handing it to `passthrough`, which reads a FALSE one\n // as rejection, turned a valid short input into a failure with an empty\n // issue array. Marking it here makes `buildTuple`'s own bail propagate\n // instead.\n (node.type === \"tuple\" && tupleRewritesShortInput(node)) ||\n // A loose/catchall object or a record hands its input back, and zod's\n // output never carries an own `__proto__` — so its output is not its\n // input whenever the key is there. Marking it here is what stops\n // `passthrough` handing the raw container up through a PARENT that\n // never looks inside it (`z.array(z.looseObject(...))`); the parent\n // rebuilds instead, and each child is scrubbed as it is built.\n (includeProtoScrub && needsProtoScrub(node)) ||\n // `z.stringbool()` replaces its accepted string with a boolean.\n node.type === \"stringBool\" ||\n // An overwrite effect (`.trim()`, `.toLowerCase()`) rewrites the string,\n // so the node's output is a new value: it has to be BUILT rather than\n // validated in place (see buildString).\n (node.type === \"string\" &&\n (node.coerce === true || node.checks.some((c) => c.kind === \"overwrite_effect\"))) ||\n ((node.type === \"number\" ||\n node.type === \"boolean\" ||\n node.type === \"bigint\" ||\n node.type === \"date\") &&\n node.coerce === true) ||\n // `.transform(fn)` replaces the value with the callback's result.\n node.type === \"effect\" ||\n (target !== undefined && rebuilds.has(target)) ||\n children(node).some((child) => rebuilds.has(child));\n if (rebuild) {\n rebuilds.add(node);\n changed = true;\n }\n }\n }\n return rebuilds;\n}\n\n/** Does `ir`, taken as a whole schema, produce a value that is not its input? */\nexport function rebuildsOutput(ir: SchemaIR): boolean {\n return rebuildSet(ir).has(ir);\n}\n\n/**\n * Does a PASSING fast check prove that the parse returns its own input?\n *\n * This is the contract behind every by-reference shortcut: `safeParse`'s\n * `if(fc(input)) return {success:true,data:input}` and, through `fc` in\n * `__zcMkv`, `parse()` / `parseAsync()` / `~standard.validate()`. It is strictly\n * stronger than \"the fast check is sound\", and two things break it:\n *\n * 1. The schema REBUILDS its output. A stripping object is the common case, and\n * it is why `z.object({ a: z.number().catch(0) })` — a strip object the\n * build pass declines because of the `.catch()` — used to answer\n * `parse({a: 1, b: 2})` with the UNSTRIPPED input while its own `safeParse`\n * correctly returned `{a: 1}`.\n *\n * 2. A plain `z.union()` with a MUTATING option. The fast form is an `||` chain,\n * which reports that SOME option accepts the input; zod returns the value\n * produced by the FIRST option that succeeds. Those differ as soon as an\n * earlier option would have claimed the input and rewritten it —\n * `z.union([z.string().catch(\"c\"), z.number()])` answers `\"c\"` for every\n * input, catch being infallible, while the chain matches `1` against the\n * number arm and hands back `1`. A DISCRIMINATED union is exempt: its\n * dispatch selects exactly one option, so which arm zod runs is never in\n * doubt (and a rewriting object option is caught by (1) anyway).\n *\n * Withheld here rather than in `fastUnion` on purpose: the `||` chain is still a\n * correct VERDICT, which is all a nested conjunct or a `.is()` guard needs, so\n * declining to emit it would cost every union-of-objects its fast path (and the\n * size-gated `__fo_` split) to fix a shortcut that only the root takes.\n */\nexport function fastResultIsInput(ir: SchemaIR): boolean {\n if (rebuildsOutput(ir)) return false;\n // 3. The output needs an own `__proto__` removed. A loose/catchall object or\n // a record hands its input back, and zod's output never carries the key,\n // so `safeParse` filters the value through `__zcPs` — which makes `data`\n // a copy exactly when the key is present. `fc` may not promise identity\n // on top of that, so `.is()` and `parse()` derive from safeParse for\n // these shapes (see ZC_PROTO_SCRUB_DECL).\n if (needsProtoScrub(ir)) return false;\n const seen = new Set<SchemaIR>();\n const ordered = (node: SchemaIR): boolean => {\n if (seen.has(node)) return false;\n seen.add(node);\n if (node.type === \"union\" && node.options.some(hasMutation)) return true;\n return children(node).some(ordered);\n };\n return !ordered(ir);\n}\n\n/**\n * True when the subtree mutates for any reason the build pass cannot reproduce —\n * `.catch()`, `z.url()`, `superRefine`. Those rewrite values in ways this pass\n * (which validates, coerces, decodes string booleans, substitutes declared\n * defaults, applies ordered string rewrites and copies) does not model, so the\n * schema keeps the eager walk.\n */\nfunction mutatesBeyondStrip(ir: SchemaIR): boolean {\n return mutatesHere(ir) || children(ir).some(mutatesBeyondStrip);\n}\n\n/**\n * Does this node rewrite values on its own account (ignoring its children, and\n * ignoring the reshaping a strip object does)? Mirrors the node-local half of\n * `hasMutation`; the recursion above supplies the other half.\n */\nfunction mutatesHere(ir: SchemaIR): boolean {\n switch (ir.type) {\n case \"string\":\n // Coercion and overwrite effects are absent: `buildString` applies them\n // in order. A `z.url()` check still is not — it trims, normalizes and\n // needs its own normalization/error semantics.\n return (\n superRefines(ir.checks) ||\n ir.checks.some((c) => c.kind === \"string_format\" && c.format === \"url\")\n );\n case \"number\":\n return superRefines(ir.checks);\n case \"boolean\":\n case \"bigint\":\n case \"date\":\n return false;\n // `default` and `effect` are absent: substituting a constant for `undefined`\n // and applying a sync transform are both modelled (see buildDefault /\n // buildEffect), and their inners are reached through `children`.\n //\n // `catch` is NOT: its catchValue callback receives a ctx carrying the inner\n // schema's collected issues, and this pass produces a sentinel instead of an\n // issue list — there is nothing to hand it.\n case \"catch\":\n case \"fallback\":\n return true;\n case \"object\":\n case \"array\":\n return superRefines(ir.checks);\n default:\n return false;\n }\n}\n\nfunction superRefines(checks: readonly { kind: string }[] | undefined): boolean {\n return checks !== undefined && checks.some((c) => c.kind === \"super_refine_effect\");\n}\n\n/**\n * Does anything STRICTLY BELOW `ir` hand back a container needing a `__proto__`\n * scrub?\n *\n * The root's by-reference shortcut can filter the value it returns\n * (`data: __zcPs(input)`), but that only reaches the OUTER container — a nested\n * one is never touched, because the shortcut does not walk. So a schema with a\n * scrub-needing descendant keeps the eager slow walk, which scrubs at every\n * level. Only the root's own scrub is shortcut-compatible.\n */\nexport function nestedNeedsProtoScrub(ir: SchemaIR): boolean {\n const seen = new Set<SchemaIR>();\n const walk = (node: SchemaIR): boolean => {\n if (seen.has(node)) return false;\n seen.add(node);\n return children(node).some((child) => needsProtoScrub(child) || walk(child));\n };\n return walk(ir);\n}\n\nfunction children(ir: SchemaIR): readonly SchemaIR[] {\n switch (ir.type) {\n case \"object\":\n return ir.catchall\n ? [...Object.values(ir.properties), ir.catchall]\n : Object.values(ir.properties);\n case \"array\":\n return [ir.element];\n case \"tuple\":\n return ir.rest === null ? ir.items : [...ir.items, ir.rest];\n case \"record\":\n case \"map\":\n return [ir.keyType, ir.valueType];\n case \"set\":\n return [ir.valueType];\n case \"union\":\n case \"discriminatedUnion\":\n return ir.options;\n case \"intersection\":\n return [ir.left, ir.right];\n case \"optional\":\n case \"nullable\":\n case \"readonly\":\n case \"default\":\n case \"catch\":\n case \"effect\":\n case \"recursionTarget\":\n case \"zodDelegate\":\n return [ir.inner];\n case \"pipe\":\n return [ir.in, ir.out];\n default:\n return [];\n }\n}\n\n/**\n * Host the whole schema as `function NAME(input){…}` returning the built value\n * or the FAIL sentinel. Returns the function name, or null when the schema is\n * not expressible as a single build pass.\n */\nexport function generateBuild(ir: SchemaIR, ctx: CodeGenContext): string | null {\n const rebuilds = rebuildSet(ir);\n if (!rebuilds.has(ir) || mutatesBeyondStrip(ir)) return null;\n // When the ONLY reason the root rebuilds is its own `__proto__` scrub, decline\n // and let the mutation-free shortcut below take it: that one keeps the fast\n // check and filters the returned value through `__zcPs`, where building would\n // pay a full single-pass walk to achieve the same thing. Measured at ~2x on a\n // 5-key `z.looseObject`, which is precisely the shape that lost the shortcut.\n // Only the root is exempt; a nested scrub still forces its parent to rebuild,\n // which is what the clause in `rebuildSet` is for.\n if (needsProtoScrub(ir) && !rebuildSet(ir, false).has(ir)) return null;\n const fail = emitFailSentinel(ctx);\n const scope: FastScope = { temps: [], used: 0 };\n const built = build(ir, \"input\", { ctx, extractable: false, fail, rebuilds, scope });\n if (built === null) return null;\n const name = emitTemp(ctx, \"vb\");\n ctx.preamble.push(\n `function ${name}(input){${declareFastTemps(scope)}${built.code}return ${built.value};}`,\n );\n return name;\n}\n\n/**\n * The build path's FAIL marker: an object compared by identity, which the build\n * function returns in place of a value and `safeParse` tests for.\n *\n * Pooled at file level rather than declared per validator. Its whole contract is\n * \"nothing a parse can produce equals this\", and that is a property of the\n * object's freshness, not of how many there are — so one `{}` serves every\n * rebuilding validator in the file, where before each allocated its own at\n * module init. Pooling by initializer text is safe for the same reason: the only\n * way a merge could hurt is if some other `{}` constant were ever RETURNED by a\n * build function, and the pool's other members are lookup tables and value\n * lists, which are only ever read from.\n */\nfunction emitFailSentinel(ctx: CodeGenContext): string {\n ctx.buildFailName ??= emitPooledConstant(ctx, \"Bf\", \"bf\", \"{}\");\n return ctx.buildFailName;\n}\n\n/**\n * Statements producing the built value of `ir` read from `input`, or null.\n *\n * Size-gated exactly like the fast path: once inlining `ir` would push the\n * function being assembled past EXTRACT_CAP, the sub-build is hosted as its own\n * `__vb_N(p)` returning value-or-FAIL and replaced by a call. Without this a\n * deeply nested schema emits one enormous build function — measured at 113 KB\n * and 354 KB on the deep fixtures — far past the bytecode size where V8 stops\n * running TurboFan on it, which would forfeit the speed this path exists for.\n */\nfunction build(ir: SchemaIR, input: string, caller: BuildGen): Built | null {\n // The dispatch skip belongs to the option's object, reached directly or\n // through a wrapper that changes nothing about object-ness or the tag;\n // any other node must not inherit it.\n const g: BuildGen =\n caller.discSkipKey !== undefined &&\n ir.type !== \"object\" &&\n ir.type !== \"readonly\" &&\n ir.type !== \"zodDelegate\"\n ? { ...caller, discSkipKey: undefined }\n : caller;\n // Resolved before the passthrough shortcut below. A back-edge carries no\n // children, so `rebuildsOutput` reads false for it — and passing it through by\n // reference would leave every nested recursive value unstripped while the\n // outermost one was rebuilt.\n if (ir.type === \"recursiveRef\") return buildRecursiveCall(ir.refId ?? 0, input, g);\n if (ir.type === \"recursionTarget\") return buildRecursionTarget(ir, input, g);\n if (!g.rebuilds.has(ir)) return passthrough(ir, input, g);\n\n const cache = (g.ctx.fastSizeCache ??= new WeakMap<SchemaIR, number>());\n if (\n g.extractable &&\n g.scope.used + predictedInlineSize(ir, input.length, cache) > EXTRACT_CAP &&\n (g.scope.used > EXTRACT_CAP || estimateFastCost(ir, cache) >= MIN_EXTRACT)\n ) {\n const hosted = hostBuild(ir, g);\n if (hosted !== null) {\n const slot = local(g, \"bh\");\n const code = `${slot}=${hosted}(${input});if(${slot}===${g.fail})return ${g.fail};`;\n g.scope.used += code.length;\n return { code, value: slot };\n }\n }\n\n // This node's extraction decision is made; its descendants get to make their\n // own, so an oversized hosted helper keeps splitting.\n // When the ONLY reason this node rebuilds is its own `__proto__` scrub —\n // nothing under it rebuilds — a validated passthrough plus that scrub IS the\n // rebuild. Taken BEFORE the builders so a plain record keeps handing its\n // input back by reference (buildRecord would copy into a fresh `{}`, which is\n // a different documented behaviour: see the output-identity divergence).\n if (needsProtoScrub(ir) && !children(ir).some((child) => g.rebuilds.has(child))) {\n return passthrough(ir, input, g);\n }\n\n const before = g.scope.used;\n const out = buildInline(ir, input, { ...g, extractable: true });\n if (out !== null) g.scope.used = before + out.code.length;\n return out;\n}\n\n/**\n * The order an object's properties are validated in: cheapest first, as the\n * fast path orders its conjuncts (see estimateRuntimeCost), so rejected input\n * is decided by a type guard rather than by the most expensive check that\n * happens to be declared first — `safeParse` on a payload with a wrong boolean\n * used to cost the email scan before it looked at the boolean. Accepted input\n * runs every property whatever the order, and the output literal is assembled\n * in shape order regardless, so a passing parse is unchanged.\n *\n * Properties whose parse can be OBSERVED to run are pinned: they keep their\n * declaration order among themselves and run after every free property, so\n * two transforms sharing state still fire in zod's order on a successful\n * parse, and a rejected one fires neither (a failing parse never guaranteed\n * that its effects ran — this pass bails at the first bad check). What counts\n * as observable is user code and value construction: a transform or\n * preprocess, a `.default()` (a function default is invoked on read), a\n * `.catch()`, a coercion (`Number(x)` reaches a `valueOf`), an overwrite, a\n * delegate, and a recursion edge, whose target is not inspected. A `.refine()`\n * is not pinned — it is a predicate, and the fast path already reorders it.\n */\nfunction orderedForBuild(\n properties: readonly [string, SchemaIR][],\n ctx: CodeGenContext,\n): readonly [string, SchemaIR][] {\n const pinned = properties.filter(([, propIR]) => orderSensitive(propIR));\n if (pinned.length === properties.length) return properties;\n const free = orderByRuntimeCost(\n properties.filter(([, propIR]) => !orderSensitive(propIR)),\n ([, propIR]) => propIR,\n ctx,\n );\n return [...free, ...pinned];\n}\n\n/** Does running this subtree do anything a caller could observe besides the verdict? */\nfunction orderSensitive(ir: SchemaIR): boolean {\n switch (ir.type) {\n case \"effect\":\n case \"default\":\n case \"catch\":\n case \"fallback\":\n case \"zodDelegate\":\n case \"recursiveRef\":\n case \"recursionTarget\":\n return true;\n case \"string\":\n if (ir.coerce === true || ir.checks.some((c) => c.kind === \"overwrite_effect\")) return true;\n break;\n case \"number\":\n case \"boolean\":\n case \"bigint\":\n case \"date\":\n if (ir.coerce === true) return true;\n break;\n default:\n break;\n }\n return children(ir).some(orderSensitive);\n}\n\n/** Host `ir`'s build in its own function over a fresh parameter; returns its name. */\nfunction hostBuild(ir: SchemaIR, g: BuildGen, discSkipKey?: string): string | null {\n const param = emitTemp(g.ctx, \"bp\");\n const scope: FastScope = { temps: [], used: 0 };\n const inner = build(ir, param, { ...g, extractable: false, scope, discSkipKey });\n if (inner === null) return null;\n const name = emitTemp(g.ctx, \"vb\");\n g.ctx.preamble.push(\n `function ${name}(${param}){${declareFastTemps(scope)}${inner.code}return ${inner.value};}`,\n );\n return name;\n}\n\nfunction buildInline(ir: SchemaIR, input: string, g: BuildGen): Built | null {\n switch (ir.type) {\n case \"object\":\n return buildObject(ir, input, g);\n case \"array\":\n return buildArray(ir, input, g);\n case \"tuple\":\n return buildTuple(ir, input, g);\n case \"record\":\n return buildRecord(ir, input, g);\n case \"optional\":\n // A default further down the chain consumes undefined into a value, so\n // the `undefined → undefined` shortcut must not fire — same rule (and\n // same helper) the slow and fast paths already apply.\n return innerAppliesDefaultOnUndefined(ir.inner)\n ? build(ir.inner, input, g)\n : buildSentinel(ir.inner, input, g, \"===undefined\", \"undefined\");\n case \"nullable\":\n // `null` short-circuits unconditionally in zod, whatever the inner is;\n // undefined flows through, so an inner default still fires.\n return buildSentinel(ir.inner, input, g, \"===null\", \"null\");\n case \"default\":\n return buildDefault(ir, input, g);\n case \"string\":\n return buildString(ir, input, g);\n case \"stringBool\":\n return buildStringBool(ir, input, g);\n case \"number\":\n case \"boolean\":\n case \"bigint\":\n case \"date\":\n return buildCoercedPrimitive(ir, input, g);\n case \"effect\":\n return buildEffect(ir, input, g);\n case \"readonly\":\n return buildReadonly(ir, input, g);\n case \"zodDelegate\":\n return build(ir.inner, input, g);\n case \"union\":\n return buildUnion(ir, input, g);\n case \"discriminatedUnion\":\n return buildDiscriminatedUnion(ir, input, g);\n default:\n // A rebuilding intersection, map or set: expressible in principle, but\n // each needs its own output-shaping rules, so they keep the eager walk\n // until there is a measured reason to add them.\n return null;\n }\n}\n\n/**\n * Host the target's build once under a name registered BEFORE its body is\n * generated, so the back-edges inside that body resolve to it.\n */\nfunction buildRecursionTarget(\n ir: SchemaIR & { type: \"recursionTarget\" },\n input: string,\n g: BuildGen,\n): Built | null {\n const table = (g.ctx.buildRecNames ??= new Map<number, string>());\n if (!table.has(ir.refId)) {\n const name = emitTemp(g.ctx, \"vbr\");\n table.set(ir.refId, name);\n const param = emitTemp(g.ctx, \"bp\");\n const scope: FastScope = { temps: [], used: 0 };\n const inner = build(ir.inner, param, { ...g, extractable: false, scope });\n if (inner === null) {\n table.delete(ir.refId);\n return null;\n }\n g.ctx.preamble.push(\n `function ${name}(${param}){${declareFastTemps(scope)}${inner.code}return ${inner.value};}`,\n );\n }\n return buildRecursiveCall(ir.refId, input, g);\n}\n\n/** Call the hosted build for a recursion target, propagating its FAIL. */\nfunction buildRecursiveCall(refId: number, input: string, g: BuildGen): Built | null {\n const name = g.ctx.buildRecNames?.get(refId);\n if (name === undefined) return null;\n const slot = local(g, \"bh\");\n return {\n code: `${slot}=${name}(${input});if(${slot}===${g.fail})return ${g.fail};`,\n value: slot,\n };\n}\n\n/**\n * Try each option in declaration order and take the first that builds — which\n * is what zod's union does with the first option that parses.\n *\n * Every option is HOSTED rather than inlined, and that is load-bearing: a\n * failing build signals with `return FAIL`, which inside the enclosing function\n * would abandon the whole parse instead of moving on to the next option. Behind\n * a call, the same signal is just a value to test.\n *\n * A union of objects that all pin one shared key to disjoint required literals\n * is dispatched instead of probed, exactly as the fast path does (see\n * detectUnionDiscriminator). Disjointness is what makes that zod's answer and\n * not merely a faster one: at most ONE option can accept a given input, so the\n * first option to succeed is the option the discriminator selects, and an\n * input whose discriminator matches no case is rejected by every option — the\n * two outcomes a probe could have produced. Unlike the fast path there is no\n * minimum option count: the options are hosted calls either way, and a switch\n * only ever replaces a run of them with one. Measured on the eight-option\n * tagged union in the benchmarks: 15.5 → 10 ns per parse, the same as the\n * `z.discriminatedUnion` spelling of it.\n *\n * PLAIN unions only. A discriminated union must not reach the probe below: zod\n * resolves it by dispatch, not by probing, and the two disagree — see\n * {@link buildDiscriminatedUnion}.\n */\nfunction buildUnion(ir: SchemaIR & { type: \"union\" }, input: string, g: BuildGen): Built | null {\n const discriminated = detectUnionDiscriminator(ir.options, 2);\n if (discriminated !== null) {\n return buildDispatch(discriminated.discriminator, discriminated.cases, ir.options, input, g);\n }\n\n const hosted: string[] = [];\n for (const option of ir.options) {\n const fn = g.rebuilds.has(option) ? hostBuild(option, g) : hostPassthrough(option, g);\n if (fn === null) return null;\n hosted.push(fn);\n }\n if (hosted.length === 0) return null;\n\n const out = local(g, \"bu\");\n let code = `${out}=${hosted[0] as string}(${input});`;\n for (const fn of hosted.slice(1)) {\n code += `if(${out}===${g.fail}){${out}=${fn}(${input});}`;\n }\n code += `if(${out}===${g.fail})return ${g.fail};`;\n return { code, value: out };\n}\n\n/**\n * Dispatch on the discriminator and build ONLY the option that value selects,\n * failing outright when it selects none — mirroring zod, which resolves the\n * option through a `discriminator value → option` map built from each option's\n * `propValues` and pushes `invalid_union` (\"No matching discriminator\") without\n * ever running an option's parse when the lookup misses.\n *\n * Probing the options in order like {@link buildUnion} does is NOT equivalent,\n * because an option can accept more than its own dispatch values. A wrapper that\n * substitutes a value contributes only the value it wraps to `propValues` while\n * its parse also accepts the input it substitutes FOR:\n * `z.literal(\"a\").default(\"a\")` dispatches on `\"a\"` alone yet parses a MISSING\n * discriminator, so sequential probing accepted `{v:\"x\"}` — output `{t:\"a\",v:\"x\"}`\n * — where zod rejects it. `.prefault()` and `.catch()` have the same shape, and\n * only escape it because neither reaches this pass today (a prefaulted schema\n * delegates to zod wholesale, and `.catch()` is refused by\n * {@link mutatesBeyondStrip}); a `.default()` is exactly what pulls the build\n * path in. The switch cannot drift that way: the dispatch table IS zod's, so an\n * unlisted discriminator reaches `default:` and fails, whatever the options\n * would have accepted on their own.\n *\n * The reverse — rejecting what zod accepts — is why `.optional()`/`.nullable()`\n * discriminators stay compiled rather than being refused here: their\n * `undefined`/`null` are in `propValues`, so they arrive as ordinary cases.\n *\n * Object-ness is proved BEFORE the discriminator is read, both because zod\n * rejects a non-object with its own `invalid_type` ahead of the lookup and\n * because the property read would throw on `null`/`undefined`.\n */\nfunction buildDiscriminatedUnion(\n ir: SchemaIR & { type: \"discriminatedUnion\" },\n input: string,\n g: BuildGen,\n): Built | null {\n return buildDispatch(ir.discriminator, ir.cases, ir.options, input, g);\n}\n\n/**\n * The switch behind {@link buildDiscriminatedUnion} and a dispatched\n * {@link buildUnion}: prove object-ness, select the option the discriminator\n * names, and build that option alone. Switches over the literal labels, as the\n * fast path does — see `emitFastDiscriminatedSwitch` for the measurement that\n * retired the ordinal-table form.\n */\nfunction buildDispatch(\n discriminator: string,\n cases: DiscriminatedUnionIR[\"cases\"],\n options: readonly SchemaIR[],\n input: string,\n g: BuildGen,\n): Built | null {\n const out = local(g, \"bd\");\n // One hosted build per REACHABLE option, keyed by option index: a multi-value\n // literal (`z.literal([\"a\",\"c\"])`) contributes several cases selecting the\n // same option, and they share the one function rather than emitting it twice.\n //\n // Each option is hosted with the discriminator as its skip key: the guard\n // below and the matched `case` have settled object-ness and the tag, so the\n // option's own object omits both (see BuildGen.discSkipKey, and the fast\n // path's FastGen.discSkipKey for the pass-through options).\n const hostedByOption = new Map<number, string>();\n let arms = \"\";\n for (const { value, option: index } of cases) {\n let fn = hostedByOption.get(index);\n if (fn === undefined) {\n const option = options[index];\n if (option === undefined) return null;\n const hosted = g.rebuilds.has(option)\n ? hostBuild(option, g, discriminator)\n : hostPassthrough(option, g, discriminator);\n if (hosted === null) return null;\n fn = hosted;\n hostedByOption.set(index, fn);\n }\n arms += `case ${literalToJs(value)}:${out}=${fn}(${input});break;`;\n }\n if (arms === \"\") return null;\n\n return {\n code:\n `if(typeof ${input}!==\"object\"||${input}===null||Array.isArray(${input}))return ${g.fail};` +\n `switch(${input}[${escapeString(discriminator)}]){${arms}default:return ${g.fail};}` +\n `if(${out}===${g.fail})return ${g.fail};`,\n value: out,\n };\n}\n\n/**\n * Host a non-rebuilding option as `value-or-FAIL`, so a union can probe it with\n * the same protocol as a rebuilding one.\n */\nfunction hostPassthrough(ir: SchemaIR, g: BuildGen, discSkipKey?: string): string | null {\n const param = emitTemp(g.ctx, \"bp\");\n const scope: FastScope = { temps: [], used: 0 };\n const expr = generateFast(ir, createFastGen(param, g.ctx, true, scope, discSkipKey));\n if (expr === null) return null;\n const name = emitTemp(g.ctx, \"vp\");\n g.ctx.preamble.push(\n `function ${name}(${param}){${declareFastTemps(scope)}return ${expr === \"true\" ? param : `(${expr})?${param}:${g.fail}`};}`,\n );\n return name;\n}\n\n/**\n * Validate in place with the Fast Path and hand the input straight back —\n * filtered through `__zcPs` for a container zod would have stripped an own\n * `__proto__` from (see ZC_PROTO_SCRUB_DECL). The filter copies only when the\n * key is present, so the ordinary value is still returned by reference.\n */\nfunction passthrough(ir: SchemaIR, input: string, g: BuildGen): Built | null {\n const scoped = createFastGen(input, g.ctx, true, g.scope, g.discSkipKey);\n const expr = generateFast(ir, scoped);\n if (expr === null) return null;\n const guard = expr === \"true\" ? \"\" : `if(!(${expr}))return ${g.fail};`;\n if (!needsProtoScrub(ir)) return { code: guard, value: input };\n const slot = local(g, \"bs\");\n const scrub = emitRuntimeHelper(g.ctx, \"__zcPs\", ZC_PROTO_SCRUB_DECL);\n return { code: `${guard}${slot}=${scrub}(${input});`, value: slot };\n}\n\n/**\n * Rebuild from the declared keys. Sound for a stripping object (that IS the\n * output) and for a strict one (unknown keys are rejected, so the declared keys\n * are the whole key set). A loose object or one with a `.catchall()` keeps keys\n * this pass does not enumerate, so those bail.\n */\n/**\n * Freeze the inner's built value, matching zod's `Object.freeze(payload.value)`.\n *\n * Sound only because `freeze` is set exclusively over a stripping object, whose\n * build ALWAYS allocates (`buildObject` assembles a fresh `__bo_N`) — so the\n * frozen value is never the caller's input. A pass-through inner would return\n * `input` here and freezing it would mutate data the caller still owns, which\n * is why the extractor withholds the flag for every other container.\n */\nfunction buildReadonly(\n ir: SchemaIR & { type: \"readonly\" },\n input: string,\n g: BuildGen,\n): Built | null {\n const built = build(ir.inner, input, g);\n if (built === null || ir.freeze !== true) return built;\n const slot = local(g, \"bz\");\n return { code: `${built.code}${slot}=Object.freeze(${built.value});`, value: slot };\n}\n\nfunction buildObject(ir: ObjectIR, input: string, g: BuildGen): Built | null {\n if (ir.catchall !== undefined) return null;\n if (ir.stripUnknownKeys !== true && ir.strict !== true) return null;\n // Both swallow an absent key's failure, which a single-pass build that fails\n // at the first bad check cannot model.\n if (ir.skipAbsentKeys !== undefined && ir.skipAbsentKeys.length > 0) return null;\n if (ir.suppressAbsentKeys !== undefined && ir.suppressAbsentKeys.length > 0) return null;\n const nonoptional = new Set(ir.nonoptionalKeys ?? []);\n // Object-level `.refine()` runs on the assembled output (below). superRefine\n // rewrites the payload, which this pass does not model — mutatesBeyondStrip\n // already rejects it, so this is a belt-and-braces narrowing of the type.\n const refines = ir.checks ?? [];\n if (refines.some((check) => check.kind !== \"refine_effect\")) return null;\n\n // A dispatched union option (see buildDispatch): the switch has proved\n // object-ness and matched this key's value, so neither is checked again.\n // Consumed here; the properties' own builds never see it.\n const skipKey = g.discSkipKey;\n const childGen: BuildGen = skipKey === undefined ? g : { ...g, discSkipKey: undefined };\n\n let code =\n skipKey === undefined\n ? `if(typeof ${input}!==\"object\"||${input}===null||Array.isArray(${input}))return ${g.fail};`\n : \"\";\n\n if (ir.strict === true) {\n const keyVar = local(g, \"bk\");\n code += `for(${keyVar} in ${input}){if(!(${keyMembershipTest(g.ctx, Object.keys(ir.properties), keyVar)}))return ${g.fail};}`;\n }\n\n // Properties are VALIDATED cheapest-first and ASSEMBLED in shape order (see\n // orderedForBuild): every value lands in its own local, so the order the\n // checks run in is free to differ from the order the keys are written in.\n const properties = parsedProperties(ir);\n const built = new Map<string, Built>();\n for (const [key, propIR] of orderedForBuild(properties, g.ctx)) {\n const keyStr = escapeString(key);\n const slot = local(g, \"bv\");\n if (key === skipKey && !g.rebuilds.has(propIR)) {\n // The matched tag. A pass-through property's output is its input, and\n // the switch compared exactly this value, so read it for the output\n // literal and skip its check (the fast path's discSkipKey does the same).\n // A REBUILDING tag — a transformed literal — is built as usual: only its\n // check is redundant, not its output.\n code += `${slot}=${input}[${keyStr}];`;\n built.set(key, { code: \"\", value: slot });\n continue;\n }\n // A required key has to be present whatever its schema makes of `undefined`.\n if (nonoptional.has(key)) code += `if(!(${keyStr} in ${input}))return ${g.fail};`;\n code += `${slot}=${input}[${keyStr}];`;\n const propBuilt = build(propIR, slot, childGen);\n if (propBuilt === null) return null;\n code += propBuilt.code;\n built.set(key, propBuilt);\n }\n const slots = properties.map(([key, propIR]) => ({\n always: outputAlwaysDefined(propIR),\n keyStr: escapeString(key),\n value: (built.get(key) as Built).value,\n }));\n\n // Same assembly the eager strip walk uses: the longest LEADING run of\n // always-present keys goes into one object literal (V8 stamps it from a\n // cached boilerplate map in a single allocation), and everything after the\n // first conditional key is appended so insertion order still matches zod.\n // The per-key test is zod's own — keep the key when the parsed value is\n // defined, or when it was present on the input at all.\n const out = local(g, \"bo\");\n const literal: string[] = [];\n let appends = \"\";\n let leading = true;\n for (const slot of slots) {\n if (leading && slot.always) {\n literal.push(`${slot.keyStr}:${slot.value}`);\n continue;\n }\n leading = false;\n appends += slot.always\n ? `${out}[${slot.keyStr}]=${slot.value};`\n : `if(${slot.value}!==undefined||(${slot.keyStr} in ${input})){${out}[${slot.keyStr}]=${slot.value};}`;\n }\n code += `${out}={${literal.join(\",\")}};${appends}`;\n // Zod parses the properties into the payload first and skips the check chain\n // when that produced issues, so a bad property suppresses the refine — which\n // this pass gets for free, having already returned FAIL at that property.\n for (const check of refines) {\n code += `if(!${emitEffectCallable(g.ctx, check as RefineEffectCheckIR)}(${out}))return ${g.fail};`;\n }\n return { code, value: out };\n}\n\nfunction buildArray(ir: SchemaIR & { type: \"array\" }, input: string, g: BuildGen): Built | null {\n // Length checks are pure predicates over `input.length`, so they hoist ahead\n // of the element loop: a size mismatch bails before a single element is\n // validated. Zod reports the per-element issue first when both fail, but the\n // build pass produces no issues — only the sentinel — and the deferred walk\n // that does produce them keeps zod's order.\n let sizes = \"\";\n const refines: RefineEffectCheckIR[] = [];\n for (const check of ir.checks) {\n switch (check.kind) {\n case \"min_length\":\n sizes += `if(${input}.length<${check.minimum})return ${g.fail};`;\n break;\n case \"max_length\":\n sizes += `if(${input}.length>${check.maximum})return ${g.fail};`;\n break;\n case \"length_equals\":\n sizes += `if(${input}.length!==${check.length})return ${g.fail};`;\n break;\n case \"refine_effect\":\n refines.push(check);\n break;\n default:\n // super_refine (rewrites the value) or a check kind not modelled here.\n return null;\n }\n }\n\n const out = local(g, \"ba\");\n const index = local(g, \"bi\");\n const elem = local(g, \"be\");\n const inner = build(ir.element, elem, g);\n if (inner === null) return null;\n let code =\n `if(!Array.isArray(${input}))return ${g.fail};` +\n sizes +\n `${out}=new Array(${input}.length);` +\n `for(${index}=0;${index}<${input}.length;${index}++){` +\n `${elem}=${input}[${index}];${inner.code}${out}[${index}]=${inner.value};}`;\n // `.refine()` sees the parsed payload, which for a rebuilding element is the\n // freshly assembled array — the same value zod hands its checks.\n for (const check of refines) {\n code += `if(!${emitEffectCallable(g.ctx, check)}(${out}))return ${g.fail};`;\n }\n return { code, value: out };\n}\n\nfunction buildTuple(ir: SchemaIR & { type: \"tuple\" }, input: string, g: BuildGen): Built | null {\n // Trailing-optional and rest handling shape the output length; keep those on\n // the eager walk rather than restating the rules here.\n if (ir.rest !== null) return null;\n if (ir.optStart !== ir.items.length) return null;\n if (ir.items.some((item) => !rejectsUndefined(item))) return null;\n\n let code = `if(!Array.isArray(${input})||${input}.length!==${ir.items.length})return ${g.fail};`;\n const values: string[] = [];\n for (const [index, itemIR] of ir.items.entries()) {\n const slot = local(g, \"bt\");\n code += `${slot}=${input}[${index}];`;\n const inner = build(itemIR as SchemaIR, slot, g);\n if (inner === null) return null;\n code += inner.code;\n values.push(inner.value);\n }\n const out = local(g, \"bl\");\n code += `${out}=[${values.join(\",\")}];`;\n return { code, value: out };\n}\n\nfunction buildRecord(ir: SchemaIR & { type: \"record\" }, input: string, g: BuildGen): Built | null {\n const plainStringKey =\n ir.keyType.type === \"string\" && ir.keyType.checks.length === 0 && ir.keyType.coerce !== true;\n if (!plainStringKey) return null;\n\n const out = local(g, \"br\");\n const keyVar = local(g, \"brk\");\n const valVar = local(g, \"brv\");\n const inner = build(ir.valueType, valVar, g);\n if (inner === null) return null;\n const hop = emitRuntimeHelper(g.ctx, \"__zcHop\", ZC_HOP_DECL);\n // `$ZodRecord` gates on `util.isPlainObject`, not the `util.isObject` the\n // object/discriminated-union builds above use — see ZC_PLAIN_DECL. And it\n // skips `__proto__` outright: here that guard is load-bearing twice over,\n // since `out[key]=value` for that key would not add a property at all but\n // REDEFINE the built object's prototype.\n const plain = emitRuntimeHelper(g.ctx, \"__zcPlain\", ZC_PLAIN_DECL);\n const code =\n `if(!${plain}(${input}))return ${g.fail};` +\n `${out}={};` +\n `for(${keyVar} in ${input}){if(${keyVar}!==\"__proto__\"&&${hop}.call(${input},${keyVar})){` +\n `${valVar}=${input}[${keyVar}];${inner.code}${out}[${keyVar}]=${inner.value};}}`;\n return { code, value: out };\n}\n\n/**\n * `.transform(fn)`: validate the inner schema, then hand its parsed value to the\n * callback. `z.preprocess(fn, schema)` reverses those two steps: call first,\n * then validate the callback's output. Returning FAIL from the inner build\n * preserves the corresponding pipe short-circuit in either direction.\n *\n * The IR reaches here only for a synchronous single-argument callback: a\n * `ctx`-taking or async transform is extracted as a `fallback` instead\n * (see extractPipe), so there is no parse context to reproduce.\n */\nfunction buildEffect(ir: SchemaIR & { type: \"effect\" }, input: string, g: BuildGen): Built | null {\n if (ir.effectKind === \"preprocess\") {\n const value = local(g, \"bpv\");\n const inner = build(ir.inner, value, g);\n if (inner === null) return null;\n return {\n code: `${value}=${emitEffectCallable(g.ctx, ir)}(${input});${inner.code}`,\n value: inner.value,\n };\n }\n\n const inner = build(ir.inner, input, g);\n if (inner === null) return null;\n const out = local(g, \"bx\");\n return {\n code: `${inner.code}${out}=${emitEffectCallable(g.ctx, ir)}(${inner.value});`,\n value: out,\n };\n}\n\n/**\n * A coercing and/or overwrite string (`z.coerce.string()`, `.trim()`,\n * `.toLowerCase()`, ...): coerce first, then emit checks one statement at a time\n * in DECLARATION order, interleaved with rewrites, because a rewrite is visible\n * to every check after it — `z.string().trim().min(1)` rejects `\" \"` where\n * `z.string().min(1).trim()` accepts it. That ordering is exactly why the fast\n * path, which sorts checks cheapest-first and returns the input unchanged, has\n * to decline these.\n *\n * Only reached for a rewriting string; a non-coercing, check-only one never\n * enters the rebuild set and is validated in place by `passthrough`.\n */\nfunction buildString(ir: SchemaIR & { type: \"string\" }, input: string, g: BuildGen): Built | null {\n const value = local(g, \"bs\");\n let code =\n ir.coerce === true\n ? `try{${value}=String(${input});}catch(_){return ${g.fail};}`\n : `if(typeof ${input}!==\"string\")return ${g.fail};${value}=${input};`;\n for (const check of ir.checks) {\n switch (check.kind) {\n case \"overwrite_effect\":\n code += `${value}=${emitEffectFn(g.ctx, check.source)}(${value});`;\n break;\n case \"refine_effect\":\n code += `if(!${emitEffectCallable(g.ctx, check)}(${value}))return ${g.fail};`;\n break;\n case \"super_refine_effect\":\n // Rewrites through zod's payload; mutatesBeyondStrip already rejects it.\n return null;\n default: {\n const expr = fastStringCheck(check, value, g.ctx);\n if (expr === null) return null; // z.url(), unknown format\n code += `if(!(${expr}))return ${g.fail};`;\n }\n }\n }\n return { code, value };\n}\n\n/**\n * `z.stringbool()`: normalize once, select the declared truthy/falsy side, and\n * return the boolean directly. The ordinary Fast Path cannot host this codec\n * because its contract returns the original input by reference; the build path\n * is designed for exactly this kind of small output rewrite.\n *\n * Case-insensitive codecs look the input up VERBATIM before lowercasing it.\n * The accepted spellings are all lowercase (see extractStringBool), so an\n * exact hit is what `toLowerCase()` would have produced anyway, and the common\n * config flag or query parameter is spelled that way already. For the hashed\n * form that is one `Map.get` in place of `toLowerCase()` plus one. A miss\n * lowercases and looks up again — unless lowercasing changed nothing, in which\n * case the second lookup would only repeat the first, so a lowercase\n * non-spelling is rejected for the price of the old path plus one string\n * compare. Measured per value on V8: 10.8 → 7.5 ns over lowercase spellings,\n * 13.5 → 10.7 ns over a mixed-case rotation. The inline form compares the raw\n * string against its few spellings first — pointer compares on internalized\n * strings — for the same trade.\n */\nfunction buildStringBool(ir: StringBoolIR, input: string, g: BuildGen): Built {\n let code = `if(typeof ${input}!==\"string\")return ${g.fail};`;\n const out = local(g, \"bb\");\n if (stringBoolUsesInline(ir)) {\n let normalized = input;\n if (!ir.caseSensitive) {\n normalized = local(g, \"bn\");\n code += `${normalized}=${stringBoolInlineHit(ir, input)}?${input}:${input}.toLowerCase();`;\n }\n const membership = (values: readonly string[]): string =>\n values.map((value) => `${normalized}===${escapeString(value)}`).join(\"||\");\n code +=\n `if(${membership(ir.truthy)}){${out}=true;}` +\n `else if(${membership(ir.falsy)}){${out}=false;}` +\n `else{return ${g.fail};}`;\n } else {\n const lookup = emitStringBoolMap(ir, g.ctx);\n code += `${out}=${lookup}.get(${input});`;\n if (!ir.caseSensitive) {\n const lowered = local(g, \"bn\");\n code +=\n `if(${out}===undefined){${lowered}=${input}.toLowerCase();` +\n `if(${lowered}!==${input}){${out}=${lookup}.get(${lowered});}}`;\n }\n code += `if(${out}===undefined)return ${g.fail};`;\n }\n return { code, value: out };\n}\n\n/** Primitive nodes whose `coerce` flag rewrites their output before checks run. */\ntype CoercedPrimitiveIR = Extract<SchemaIR, { type: \"number\" | \"boolean\" | \"bigint\" | \"date\" }>;\n\n/**\n * Coerce once into a local, then reuse the ordinary Fast Path as the acceptance\n * predicate over the converted value. The build path only needs a verdict on\n * its hot pass; if it fails, the existing deferred slow walk reruns the original\n * coercing schema and produces Zod-identical issues.\n *\n * Number/BigInt/Date conversion can invoke user hooks and throw. Zod catches\n * those throws and reports invalid_type, so the sentinel branch does the same\n * without allocating an issue. Boolean never invokes conversion hooks.\n */\nfunction buildCoercedPrimitive(ir: CoercedPrimitiveIR, input: string, g: BuildGen): Built | null {\n if (ir.coerce !== true) return null;\n const value = local(g, \"bc\");\n let conversion: string;\n switch (ir.type) {\n case \"number\":\n conversion = `Number(${input})`;\n break;\n case \"boolean\":\n conversion = `Boolean(${input})`;\n break;\n case \"bigint\":\n conversion = `BigInt(${input})`;\n break;\n case \"date\":\n conversion = `new Date(${input})`;\n break;\n }\n\n // A fresh shallow node is intentional: only the coerce flag changes. The\n // existing primitive generator remains the single source of truth for every\n // range, format, refine and finite/valid-date check.\n const predicate = generateFast(\n { ...ir, coerce: false },\n createFastGen(value, g.ctx, true, g.scope),\n );\n if (predicate === null) return null;\n\n const assign = `${value}=${conversion};`;\n const code = ir.type === \"boolean\" ? assign : `try{${assign}}catch(_){return ${g.fail};}`;\n return {\n code: code + (predicate === \"true\" ? \"\" : `if(!(${predicate}))return ${g.fail};`),\n value,\n };\n}\n\n/**\n * `.default(v)`: `undefined` yields the declared value without running the\n * inner schema, anything else parses normally — the same two branches\n * `slowDefault` emits, reading the value off the retained schema so a\n * reference-typed default keeps zod's identity (one shared object, not a copy).\n *\n * The substituted value is not validated. The by-reference fast form refuses\n * `undefined` for that reason (it would hand the input back, not the default);\n * the acceptance form `.is()` runs accepts it, as the schema does — see\n * fastDefault.\n */\nfunction buildDefault(\n ir: SchemaIR & { type: \"default\" },\n input: string,\n g: BuildGen,\n): Built | null {\n const inner = build(ir.inner, input, g);\n if (inner === null) return null;\n const out = local(g, \"bq\");\n const value = defaultValueExpr(ir);\n // Zod re-applies the default when the inner returns undefined for a defined\n // input; only emitted when the inner can actually do that.\n const reapply = needsPostInnerDefault(ir) ? `if(${out}===undefined){${out}=${value};}` : \"\";\n return {\n code:\n `if(${input}===undefined){${out}=${value};}` +\n `else{${inner.code}${out}=${inner.value};${reapply}}`,\n value: out,\n };\n}\n\n/** `optional` / `nullable` around a rebuilding inner: pass the sentinel through. */\nfunction buildSentinel(\n innerIR: SchemaIR,\n input: string,\n g: BuildGen,\n test: string,\n sentinel: string,\n): Built | null {\n const inner = build(innerIR, input, g);\n if (inner === null) return null;\n const out = local(g, \"bw\");\n return {\n code: `if(${input}${test}){${out}=${sentinel};}else{${inner.code}${out}=${inner.value};}`,\n value: out,\n };\n}\n\n/** Allocate a `var` the hosted build function declares. */\nfunction local(g: BuildGen, prefix: string): string {\n const name = emitTemp(g.ctx, prefix);\n g.scope.temps.push(name);\n return name;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8HA,SAAS,WAAW,MAAgB,oBAAoB,MAA6B;CACnF,MAAM,0BAAU,IAAI,IAAsB,CAAC,CAAC,GAAG,IAAI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AC3C;CACA,IAAI,cAAc,MAAM,OAAO;CAE/B,MAAM,SAAS,GAAG,MAAM,GAAG,WAAW;CAEtC,OAAO;EACL,OAFW,GAAG,SAAS,YAAY,SAAS,OAAO,OAAO,mBAAmB,EAAE,KAAK,QAEtE,cAAc,SAAS,KAAK,QAAQ,UAAU,WAAW,EAAE,KAAK;EAC9E;CACF;AACF;;;;;;;;;;;;AAaA,SAAS,aACP,IACA,OACA,GACc;CACd,MAAM,QAAQ,MAAM,GAAG,OAAO,OAAO,CAAC;CACtC,IAAI,UAAU,MAAM,OAAO;CAC3B,MAAM,MAAM,MAAM,GAAG,IAAI;CACzB,MAAM,QAAQ,iBAAiB,EAAE;CAGjC,MAAM,UAAU,sBAAsB,EAAE,IAAI,MAAM,IAAI,gBAAgB,IAAI,GAAG,MAAM,MAAM;CACzF,OAAO;EACL,MACE,MAAM,MAAM,gBAAgB,IAAI,GAAG,MAAM,SACjC,MAAM,OAAO,IAAI,GAAG,MAAM,MAAM,GAAG,QAAQ;EACrD,OAAO;CACT;AACF;;AAGA,SAAS,cACP,SACA,OACA,GACA,MACA,UACc;CACd,MAAM,QAAQ,MAAM,SAAS,OAAO,CAAC;CACrC,IAAI,UAAU,MAAM,OAAO;CAC3B,MAAM,MAAM,MAAM,GAAG,IAAI;CACzB,OAAO;EACL,MAAM,MAAM,QAAQ,KAAK,IAAI,IAAI,GAAG,SAAS,SAAS,MAAM,OAAO,IAAI,GAAG,MAAM,MAAM;EACtF,OAAO;CACT;AACF;;AAGA,SAAS,MAAM,GAAa,QAAwB;CAClD,MAAM,OAAO,SAAS,EAAE,KAAK,MAAM;CACnC,EAAE,MAAM,MAAM,KAAK,IAAI;CACvB,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"build-path.js","names":[],"sources":["../../../src/core/codegen/build-path.ts"],"sourcesContent":["/**\n * Build Path: one uninstrumented pass that VALIDATES and BUILDS rewritten\n * output together, abandoning the whole parse at the first failing check.\n *\n * `z.object()` strips unknown keys, so a successful parse cannot return the\n * input by reference — it must produce a fresh object. That rules out the Fast\n * Path (whose contract is `data === input`), and before this the only remaining\n * option was the eager slow walk: a fully instrumented traversal that collects\n * issues on every parse, valid or not.\n *\n * Two passes are wasteful in either direction. Validating first and building\n * afterwards reads every property twice (measured 29.7 ns vs 21.6 for the slow\n * walk on a 6-field object). Building with issue collection pays the\n * instrumentation even when nothing fails. Doing both in ONE pass, with a\n * sentinel instead of an issues array, beats both — and a failure costs only\n * the checks up to the first bad one, because the issue-producing walk is\n * deferred into `.error` exactly as `__zcFinD` does for mutation-free schemas:\n *\n * object clean object invalid array(8) invalid\n * slow walk 21.6 ns 30.4 ns 197.5 ns\n * build path 18.1 ns 7.7 ns 9.8 ns\n *\n * A subtree that rebuilds nothing is validated with its existing Fast Path\n * expression and passed through by reference, so only nodes that genuinely\n * produce a new value need code here; anything else returns null and keeps the\n * eager walk.\n *\n * Coverage is what decides whether this pass is reached at all, because it is\n * all-or-nothing per schema: ONE unmodelled node anywhere in the tree costs the\n * whole schema its single-pass parse. Modelled, beyond the stripping containers\n * this started with: array size checks and `.refine()`, object-level `.refine()`,\n * `.default()` substitution, ordered string rewrites (`.trim()`,\n * `.toLowerCase()`), sync `.transform()`, `z.stringbool()`, and the five native\n * coercions (`string`, `number`, `boolean`, `bigint`, `date`). Still declined, via\n * {@link mutatesBeyondStrip} — `.catch()` (its callback wants the inner schema's\n * issue list, which this pass never builds), `z.url()`, and `superRefine`.\n */\n\nimport type {\n DiscriminatedUnionIR,\n ObjectIR,\n RefineEffectCheckIR,\n SchemaIR,\n StringBoolIR,\n} from \"../types.js\";\nimport type { CodeGenContext, FastScope } from \"./context.js\";\nimport {\n declareFastTemps,\n emitEffectCallable,\n emitEffectFn,\n emitPooledConstant,\n emitRuntimeHelper,\n emitTemp,\n escapeString,\n hasMutation,\n keyMembershipTest,\n literalToJs,\n needsProtoScrub,\n outputAlwaysDefined,\n rejectsUndefined,\n tupleRewritesShortInput,\n} from \"./context.js\";\nimport { createFastGen, generateFast } from \"./fast-path.js\";\nimport {\n EXTRACT_CAP,\n estimateFastCost,\n MIN_EXTRACT,\n orderByRuntimeCost,\n predictedInlineSize,\n} from \"./fast-size.js\";\nimport { ZC_ASYNC_DECL, ZC_HOP_DECL, ZC_PLAIN_DECL, ZC_PROTO_SCRUB_DECL } from \"./issue-decls.js\";\nimport { defaultValueExpr, needsPostInnerDefault } from \"./schemas/default.js\";\nimport { parsedProperties } from \"./schemas/object.js\";\nimport { innerAppliesDefaultOnUndefined } from \"./schemas/optional.js\";\nimport { detectUnionDiscriminator } from \"./schemas/discriminated-union.js\";\nimport { fastStringCheck } from \"./schemas/string.js\";\nimport {\n emitStringBoolMap,\n stringBoolInlineHit,\n stringBoolUsesInline,\n} from \"./schemas/string-bool.js\";\n\n/** Statements that leave the built value in `value`, or `return <FAIL>` on failure. */\ninterface Built {\n code: string;\n value: string;\n}\n\ninterface BuildGen {\n ctx: CodeGenContext;\n /** Identifier of the per-validator FAIL sentinel. */\n fail: string;\n /** `var` temps and running emitted size of the function being assembled. */\n scope: FastScope;\n /**\n * May THIS node be hosted in its own function? False for the node a hosted\n * build was created for — it already IS that function, so re-hosting it would\n * recurse forever. Children are always extractable, letting an oversized\n * helper split further.\n */\n extractable: boolean;\n /** Nodes of the root schema that rebuild (see rebuildSet). */\n rebuilds: ReadonlySet<SchemaIR>;\n /**\n * Set on the gen for a dispatched union option (see buildDispatch): the\n * discriminator key. The switch that selected the option has already proved\n * the input is an object and matched this key's value, so `buildObject`\n * emits neither check again. Consumed by the first object reached — directly\n * or through a transparent wrapper — and never inherited past it.\n */\n discSkipKey?: string | undefined;\n}\n\n/**\n * Which nodes of `root` produce a value that is not their input — a stripping\n * object, coercion, codec, default, overwrite or transform, including\n * containers that contain one. Everything else can be validated in place and\n * passed through, which is what keeps this generator small.\n *\n * Computed as a fixpoint rather than a plain walk because of recursion: a\n * `recursiveRef` is a back-edge with no children, so a local walk reads false\n * for it and would pass the whole recursive subtree through by reference —\n * leaving every nested value unstripped while the outermost one was rebuilt.\n * Resolving the ref against its target closes the cycle, and iterating to a\n * fixpoint settles the mutual dependency between the two.\n */\nfunction rebuildSet(root: SchemaIR, includeProtoScrub = true): ReadonlySet<SchemaIR> {\n const targets = new Map<number, SchemaIR>([[0, root]]);\n const nodes: SchemaIR[] = [];\n const seen = new Set<SchemaIR>();\n const collect = (node: SchemaIR): void => {\n if (seen.has(node)) return;\n seen.add(node);\n nodes.push(node);\n if (node.type === \"recursionTarget\") targets.set(node.refId, node.inner);\n for (const child of children(node)) collect(child);\n };\n collect(root);\n\n const rebuilds = new Set<SchemaIR>();\n for (let changed = true; changed;) {\n changed = false;\n for (const node of nodes) {\n if (rebuilds.has(node)) continue;\n const target = node.type === \"recursiveRef\" ? targets.get(node.refId ?? 0) : undefined;\n const rebuild =\n (node.type === \"object\" && node.stripUnknownKeys === true) ||\n // A freezing readonly's output is `Object.freeze(inner)` — a value the\n // caller never handed us, so it must be BUILT rather than passed\n // through. Marking it here is also what makes `rebuildsOutput` true and\n // so withholds every by-reference shortcut above it.\n (node.type === \"readonly\" && node.freeze === true) ||\n // `.default()` substitutes its own value for `undefined`, so its output\n // is not its input even when the inner schema passes through — it must\n // never be handed to `passthrough`, whose fast check would reject the\n // absent value outright.\n node.type === \"default\" ||\n // A tuple whose output can differ from a SHORT input it accepts —\n // `z.tuple([z.any()]).rest(z.number())` answers `[]` with `[undefined]`\n // — is not its own input either. `fastTuple` narrows exactly those\n // slots to \"present\" (sound for the root shortcut, which only reads a\n // TRUE result), so handing it to `passthrough`, which reads a FALSE one\n // as rejection, turned a valid short input into a failure with an empty\n // issue array. Marking it here makes `buildTuple`'s own bail propagate\n // instead.\n (node.type === \"tuple\" && tupleRewritesShortInput(node)) ||\n // A loose/catchall object or a record hands its input back, and zod's\n // output never carries an own `__proto__` — so its output is not its\n // input whenever the key is there. Marking it here is what stops\n // `passthrough` handing the raw container up through a PARENT that\n // never looks inside it (`z.array(z.looseObject(...))`); the parent\n // rebuilds instead, and each child is scrubbed as it is built.\n (includeProtoScrub && needsProtoScrub(node)) ||\n // `z.stringbool()` replaces its accepted string with a boolean.\n node.type === \"stringBool\" ||\n // An overwrite effect (`.trim()`, `.toLowerCase()`) rewrites the string,\n // so the node's output is a new value: it has to be BUILT rather than\n // validated in place (see buildString).\n (node.type === \"string\" &&\n (node.coerce === true || node.checks.some((c) => c.kind === \"overwrite_effect\"))) ||\n ((node.type === \"number\" ||\n node.type === \"boolean\" ||\n node.type === \"bigint\" ||\n node.type === \"date\") &&\n node.coerce === true) ||\n // `.transform(fn)` replaces the value with the callback's result.\n node.type === \"effect\" ||\n (target !== undefined && rebuilds.has(target)) ||\n children(node).some((child) => rebuilds.has(child));\n if (rebuild) {\n rebuilds.add(node);\n changed = true;\n }\n }\n }\n return rebuilds;\n}\n\n/** Does `ir`, taken as a whole schema, produce a value that is not its input? */\nexport function rebuildsOutput(ir: SchemaIR): boolean {\n return rebuildSet(ir).has(ir);\n}\n\n/**\n * Does a PASSING fast check prove that the parse returns its own input?\n *\n * This is the contract behind every by-reference shortcut: `safeParse`'s\n * `if(fc(input)) return {success:true,data:input}` and, through `fc` in\n * `__zcMkv`, `parse()` / `parseAsync()` / `~standard.validate()`. It is strictly\n * stronger than \"the fast check is sound\", and two things break it:\n *\n * 1. The schema REBUILDS its output. A stripping object is the common case, and\n * it is why `z.object({ a: z.number().catch(0) })` — a strip object the\n * build pass declines because of the `.catch()` — used to answer\n * `parse({a: 1, b: 2})` with the UNSTRIPPED input while its own `safeParse`\n * correctly returned `{a: 1}`.\n *\n * 2. A plain `z.union()` with a MUTATING option. The fast form is an `||` chain,\n * which reports that SOME option accepts the input; zod returns the value\n * produced by the FIRST option that succeeds. Those differ as soon as an\n * earlier option would have claimed the input and rewritten it —\n * `z.union([z.string().catch(\"c\"), z.number()])` answers `\"c\"` for every\n * input, catch being infallible, while the chain matches `1` against the\n * number arm and hands back `1`. A DISCRIMINATED union is exempt: its\n * dispatch selects exactly one option, so which arm zod runs is never in\n * doubt (and a rewriting object option is caught by (1) anyway).\n *\n * Withheld here rather than in `fastUnion` on purpose: the `||` chain is still a\n * correct VERDICT, which is all a nested conjunct or a `.is()` guard needs, so\n * declining to emit it would cost every union-of-objects its fast path (and the\n * size-gated `__fo_` split) to fix a shortcut that only the root takes.\n */\nexport function fastResultIsInput(ir: SchemaIR): boolean {\n if (rebuildsOutput(ir)) return false;\n // 3. The output needs an own `__proto__` removed. A loose/catchall object or\n // a record hands its input back, and zod's output never carries the key,\n // so `safeParse` filters the value through `__zcPs` — which makes `data`\n // a copy exactly when the key is present. `fc` may not promise identity\n // on top of that, so `.is()` and `parse()` derive from safeParse for\n // these shapes (see ZC_PROTO_SCRUB_DECL).\n if (needsProtoScrub(ir)) return false;\n const seen = new Set<SchemaIR>();\n const ordered = (node: SchemaIR): boolean => {\n if (seen.has(node)) return false;\n seen.add(node);\n if (node.type === \"union\" && node.options.some(hasMutation)) return true;\n return children(node).some(ordered);\n };\n return !ordered(ir);\n}\n\n/**\n * True when the subtree mutates for any reason the build pass cannot reproduce —\n * `.catch()`, `z.url()`, `superRefine`. Those rewrite values in ways this pass\n * (which validates, coerces, decodes string booleans, substitutes declared\n * defaults, applies ordered string rewrites and copies) does not model, so the\n * schema keeps the eager walk.\n */\nfunction mutatesBeyondStrip(ir: SchemaIR): boolean {\n return mutatesHere(ir) || children(ir).some(mutatesBeyondStrip);\n}\n\n/**\n * Does this node rewrite values on its own account (ignoring its children, and\n * ignoring the reshaping a strip object does)? Mirrors the node-local half of\n * `hasMutation`; the recursion above supplies the other half.\n */\nfunction mutatesHere(ir: SchemaIR): boolean {\n switch (ir.type) {\n case \"string\":\n // Coercion and overwrite effects are absent: `buildString` applies them\n // in order. A `z.url()` check still is not — it trims, normalizes and\n // needs its own normalization/error semantics.\n return (\n superRefines(ir.checks) ||\n ir.checks.some((c) => c.kind === \"string_format\" && c.format === \"url\")\n );\n case \"number\":\n return superRefines(ir.checks);\n case \"boolean\":\n case \"bigint\":\n case \"date\":\n return false;\n // `default` and `effect` are absent: substituting a constant for `undefined`\n // and applying a sync transform are both modelled (see buildDefault /\n // buildEffect), and their inners are reached through `children`.\n //\n // `catch` is NOT: its catchValue callback receives a ctx carrying the inner\n // schema's collected issues, and this pass produces a sentinel instead of an\n // issue list — there is nothing to hand it.\n case \"catch\":\n case \"fallback\":\n return true;\n case \"object\":\n case \"array\":\n return superRefines(ir.checks);\n default:\n return false;\n }\n}\n\nfunction superRefines(checks: readonly { kind: string }[] | undefined): boolean {\n return checks !== undefined && checks.some((c) => c.kind === \"super_refine_effect\");\n}\n\n/**\n * Does anything STRICTLY BELOW `ir` hand back a container needing a `__proto__`\n * scrub?\n *\n * The root's by-reference shortcut can filter the value it returns\n * (`data: __zcPs(input)`), but that only reaches the OUTER container — a nested\n * one is never touched, because the shortcut does not walk. So a schema with a\n * scrub-needing descendant keeps the eager slow walk, which scrubs at every\n * level. Only the root's own scrub is shortcut-compatible.\n */\nexport function nestedNeedsProtoScrub(ir: SchemaIR): boolean {\n const seen = new Set<SchemaIR>();\n const walk = (node: SchemaIR): boolean => {\n if (seen.has(node)) return false;\n seen.add(node);\n return children(node).some((child) => needsProtoScrub(child) || walk(child));\n };\n return walk(ir);\n}\n\nfunction children(ir: SchemaIR): readonly SchemaIR[] {\n switch (ir.type) {\n case \"object\":\n return ir.catchall\n ? [...Object.values(ir.properties), ir.catchall]\n : Object.values(ir.properties);\n case \"array\":\n return [ir.element];\n case \"tuple\":\n return ir.rest === null ? ir.items : [...ir.items, ir.rest];\n case \"record\":\n case \"map\":\n return [ir.keyType, ir.valueType];\n case \"set\":\n return [ir.valueType];\n case \"union\":\n case \"discriminatedUnion\":\n return ir.options;\n case \"intersection\":\n return [ir.left, ir.right];\n case \"optional\":\n case \"nullable\":\n case \"readonly\":\n case \"default\":\n case \"catch\":\n case \"effect\":\n case \"recursionTarget\":\n case \"zodDelegate\":\n return [ir.inner];\n case \"pipe\":\n return [ir.in, ir.out];\n default:\n return [];\n }\n}\n\n/**\n * Host the whole schema as `function NAME(input){…}` returning the built value\n * or the FAIL sentinel. Returns the function name, or null when the schema is\n * not expressible as a single build pass.\n */\nexport function generateBuild(ir: SchemaIR, ctx: CodeGenContext): string | null {\n const rebuilds = rebuildSet(ir);\n if (!rebuilds.has(ir) || mutatesBeyondStrip(ir)) return null;\n // When the ONLY reason the root rebuilds is its own `__proto__` scrub, decline\n // and let the mutation-free shortcut below take it: that one keeps the fast\n // check and filters the returned value through `__zcPs`, where building would\n // pay a full single-pass walk to achieve the same thing. Measured at ~2x on a\n // 5-key `z.looseObject`, which is precisely the shape that lost the shortcut.\n // Only the root is exempt; a nested scrub still forces its parent to rebuild,\n // which is what the clause in `rebuildSet` is for.\n if (needsProtoScrub(ir) && !rebuildSet(ir, false).has(ir)) return null;\n const fail = emitFailSentinel(ctx);\n const scope: FastScope = { temps: [], used: 0 };\n const built = build(ir, \"input\", { ctx, extractable: false, fail, rebuilds, scope });\n if (built === null) return null;\n const name = emitTemp(ctx, \"vb\");\n ctx.preamble.push(\n `function ${name}(input){${declareFastTemps(scope)}${built.code}return ${built.value};}`,\n );\n return name;\n}\n\n/**\n * The build path's FAIL marker: an object compared by identity, which the build\n * function returns in place of a value and `safeParse` tests for.\n *\n * Pooled at file level rather than declared per validator. Its whole contract is\n * \"nothing a parse can produce equals this\", and that is a property of the\n * object's freshness, not of how many there are — so one `{}` serves every\n * rebuilding validator in the file, where before each allocated its own at\n * module init. Pooling by initializer text is safe for the same reason: the only\n * way a merge could hurt is if some other `{}` constant were ever RETURNED by a\n * build function, and the pool's other members are lookup tables and value\n * lists, which are only ever read from.\n */\nfunction emitFailSentinel(ctx: CodeGenContext): string {\n ctx.buildFailName ??= emitPooledConstant(ctx, \"Bf\", \"bf\", \"{}\");\n return ctx.buildFailName;\n}\n\n/**\n * Statements producing the built value of `ir` read from `input`, or null.\n *\n * Size-gated exactly like the fast path: once inlining `ir` would push the\n * function being assembled past EXTRACT_CAP, the sub-build is hosted as its own\n * `__vb_N(p)` returning value-or-FAIL and replaced by a call. Without this a\n * deeply nested schema emits one enormous build function — measured at 113 KB\n * and 354 KB on the deep fixtures — far past the bytecode size where V8 stops\n * running TurboFan on it, which would forfeit the speed this path exists for.\n */\nfunction build(ir: SchemaIR, input: string, caller: BuildGen): Built | null {\n // The dispatch skip belongs to the option's object, reached directly or\n // through a wrapper that changes nothing about object-ness or the tag;\n // any other node must not inherit it.\n const g: BuildGen =\n caller.discSkipKey !== undefined &&\n ir.type !== \"object\" &&\n ir.type !== \"readonly\" &&\n ir.type !== \"zodDelegate\"\n ? { ...caller, discSkipKey: undefined }\n : caller;\n // Resolved before the passthrough shortcut below. A back-edge carries no\n // children, so `rebuildsOutput` reads false for it — and passing it through by\n // reference would leave every nested recursive value unstripped while the\n // outermost one was rebuilt.\n if (ir.type === \"recursiveRef\") return buildRecursiveCall(ir.refId ?? 0, input, g);\n if (ir.type === \"recursionTarget\") return buildRecursionTarget(ir, input, g);\n if (!g.rebuilds.has(ir)) return passthrough(ir, input, g);\n\n const cache = (g.ctx.fastSizeCache ??= new WeakMap<SchemaIR, number>());\n if (\n g.extractable &&\n g.scope.used + predictedInlineSize(ir, input.length, cache) > EXTRACT_CAP &&\n (g.scope.used > EXTRACT_CAP || estimateFastCost(ir, cache) >= MIN_EXTRACT)\n ) {\n const hosted = hostBuild(ir, g);\n if (hosted !== null) {\n const slot = local(g, \"bh\");\n const code = `${slot}=${hosted}(${input});if(${slot}===${g.fail})return ${g.fail};`;\n g.scope.used += code.length;\n return { code, value: slot };\n }\n }\n\n // This node's extraction decision is made; its descendants get to make their\n // own, so an oversized hosted helper keeps splitting.\n // When the ONLY reason this node rebuilds is its own `__proto__` scrub —\n // nothing under it rebuilds — a validated passthrough plus that scrub IS the\n // rebuild. Taken BEFORE the builders so a plain record keeps handing its\n // input back by reference (buildRecord would copy into a fresh `{}`, which is\n // a different documented behaviour: see the output-identity divergence).\n if (needsProtoScrub(ir) && !children(ir).some((child) => g.rebuilds.has(child))) {\n return passthrough(ir, input, g);\n }\n\n const before = g.scope.used;\n const out = buildInline(ir, input, { ...g, extractable: true });\n if (out !== null) g.scope.used = before + out.code.length;\n return out;\n}\n\n/**\n * The order an object's properties are validated in: cheapest first, as the\n * fast path orders its conjuncts (see estimateRuntimeCost), so rejected input\n * is decided by a type guard rather than by the most expensive check that\n * happens to be declared first — `safeParse` on a payload with a wrong boolean\n * used to cost the email scan before it looked at the boolean. Accepted input\n * runs every property whatever the order, and the output literal is assembled\n * in shape order regardless, so a passing parse is unchanged.\n *\n * Properties whose parse can be OBSERVED to run are pinned: they keep their\n * declaration order among themselves and run after every free property, so\n * two transforms sharing state still fire in zod's order on a successful\n * parse, and a rejected one fires neither (a failing parse never guaranteed\n * that its effects ran — this pass bails at the first bad check). What counts\n * as observable is user code and value construction: a transform or\n * preprocess, a `.default()` (a function default is invoked on read), a\n * `.catch()`, a coercion (`Number(x)` reaches a `valueOf`), an overwrite, a\n * delegate, and a recursion edge, whose target is not inspected. A `.refine()`\n * is not pinned — it is a predicate, and the fast path already reorders it.\n */\nfunction orderedForBuild(\n properties: readonly [string, SchemaIR][],\n ctx: CodeGenContext,\n): readonly [string, SchemaIR][] {\n const pinned = properties.filter(([, propIR]) => orderSensitive(propIR));\n if (pinned.length === properties.length) return properties;\n const free = orderByRuntimeCost(\n properties.filter(([, propIR]) => !orderSensitive(propIR)),\n ([, propIR]) => propIR,\n ctx,\n );\n return [...free, ...pinned];\n}\n\n/** Does running this subtree do anything a caller could observe besides the verdict? */\nfunction orderSensitive(ir: SchemaIR): boolean {\n switch (ir.type) {\n case \"effect\":\n case \"default\":\n case \"catch\":\n case \"fallback\":\n case \"zodDelegate\":\n case \"recursiveRef\":\n case \"recursionTarget\":\n return true;\n case \"string\":\n if (ir.coerce === true || ir.checks.some((c) => c.kind === \"overwrite_effect\")) return true;\n break;\n case \"number\":\n case \"boolean\":\n case \"bigint\":\n case \"date\":\n if (ir.coerce === true) return true;\n break;\n default:\n break;\n }\n return children(ir).some(orderSensitive);\n}\n\n/** Host `ir`'s build in its own function over a fresh parameter; returns its name. */\nfunction hostBuild(ir: SchemaIR, g: BuildGen, discSkipKey?: string): string | null {\n const param = emitTemp(g.ctx, \"bp\");\n const scope: FastScope = { temps: [], used: 0 };\n const inner = build(ir, param, { ...g, extractable: false, scope, discSkipKey });\n if (inner === null) return null;\n const name = emitTemp(g.ctx, \"vb\");\n g.ctx.preamble.push(\n `function ${name}(${param}){${declareFastTemps(scope)}${inner.code}return ${inner.value};}`,\n );\n return name;\n}\n\nfunction buildInline(ir: SchemaIR, input: string, g: BuildGen): Built | null {\n switch (ir.type) {\n case \"object\":\n return buildObject(ir, input, g);\n case \"array\":\n return buildArray(ir, input, g);\n case \"tuple\":\n return buildTuple(ir, input, g);\n case \"record\":\n return buildRecord(ir, input, g);\n case \"optional\":\n // A default further down the chain consumes undefined into a value, so\n // the `undefined → undefined` shortcut must not fire — same rule (and\n // same helper) the slow and fast paths already apply.\n return innerAppliesDefaultOnUndefined(ir.inner)\n ? build(ir.inner, input, g)\n : buildSentinel(ir.inner, input, g, \"===undefined\", \"undefined\");\n case \"nullable\":\n // `null` short-circuits unconditionally in zod, whatever the inner is;\n // undefined flows through, so an inner default still fires.\n return buildSentinel(ir.inner, input, g, \"===null\", \"null\");\n case \"default\":\n return buildDefault(ir, input, g);\n case \"string\":\n return buildString(ir, input, g);\n case \"stringBool\":\n return buildStringBool(ir, input, g);\n case \"number\":\n case \"boolean\":\n case \"bigint\":\n case \"date\":\n return buildCoercedPrimitive(ir, input, g);\n case \"effect\":\n return buildEffect(ir, input, g);\n case \"readonly\":\n return buildReadonly(ir, input, g);\n case \"zodDelegate\":\n return build(ir.inner, input, g);\n case \"union\":\n return buildUnion(ir, input, g);\n case \"discriminatedUnion\":\n return buildDiscriminatedUnion(ir, input, g);\n default:\n // A rebuilding intersection, map or set: expressible in principle, but\n // each needs its own output-shaping rules, so they keep the eager walk\n // until there is a measured reason to add them.\n return null;\n }\n}\n\n/**\n * Host the target's build once under a name registered BEFORE its body is\n * generated, so the back-edges inside that body resolve to it.\n */\nfunction buildRecursionTarget(\n ir: SchemaIR & { type: \"recursionTarget\" },\n input: string,\n g: BuildGen,\n): Built | null {\n const table = (g.ctx.buildRecNames ??= new Map<number, string>());\n if (!table.has(ir.refId)) {\n const name = emitTemp(g.ctx, \"vbr\");\n table.set(ir.refId, name);\n const param = emitTemp(g.ctx, \"bp\");\n const scope: FastScope = { temps: [], used: 0 };\n const inner = build(ir.inner, param, { ...g, extractable: false, scope });\n if (inner === null) {\n table.delete(ir.refId);\n return null;\n }\n g.ctx.preamble.push(\n `function ${name}(${param}){${declareFastTemps(scope)}${inner.code}return ${inner.value};}`,\n );\n }\n return buildRecursiveCall(ir.refId, input, g);\n}\n\n/** Call the hosted build for a recursion target, propagating its FAIL. */\nfunction buildRecursiveCall(refId: number, input: string, g: BuildGen): Built | null {\n const name = g.ctx.buildRecNames?.get(refId);\n if (name === undefined) return null;\n const slot = local(g, \"bh\");\n return {\n code: `${slot}=${name}(${input});if(${slot}===${g.fail})return ${g.fail};`,\n value: slot,\n };\n}\n\n/**\n * Try each option in declaration order and take the first that builds — which\n * is what zod's union does with the first option that parses.\n *\n * Every option is HOSTED rather than inlined, and that is load-bearing: a\n * failing build signals with `return FAIL`, which inside the enclosing function\n * would abandon the whole parse instead of moving on to the next option. Behind\n * a call, the same signal is just a value to test.\n *\n * A union of objects that all pin one shared key to disjoint required literals\n * is dispatched instead of probed, exactly as the fast path does (see\n * detectUnionDiscriminator). Disjointness is what makes that zod's answer and\n * not merely a faster one: at most ONE option can accept a given input, so the\n * first option to succeed is the option the discriminator selects, and an\n * input whose discriminator matches no case is rejected by every option — the\n * two outcomes a probe could have produced. Unlike the fast path there is no\n * minimum option count: the options are hosted calls either way, and a switch\n * only ever replaces a run of them with one. Measured on the eight-option\n * tagged union in the benchmarks: 15.5 → 10 ns per parse, the same as the\n * `z.discriminatedUnion` spelling of it.\n *\n * PLAIN unions only. A discriminated union must not reach the probe below: zod\n * resolves it by dispatch, not by probing, and the two disagree — see\n * {@link buildDiscriminatedUnion}.\n */\nfunction buildUnion(ir: SchemaIR & { type: \"union\" }, input: string, g: BuildGen): Built | null {\n const discriminated = detectUnionDiscriminator(ir.options, 2);\n if (discriminated !== null) {\n return buildDispatch(discriminated.discriminator, discriminated.cases, ir.options, input, g);\n }\n\n const hosted: string[] = [];\n for (const option of ir.options) {\n const fn = g.rebuilds.has(option) ? hostBuild(option, g) : hostPassthrough(option, g);\n if (fn === null) return null;\n hosted.push(fn);\n }\n if (hosted.length === 0) return null;\n\n const out = local(g, \"bu\");\n let code = `${out}=${hosted[0] as string}(${input});`;\n for (const fn of hosted.slice(1)) {\n code += `if(${out}===${g.fail}){${out}=${fn}(${input});}`;\n }\n code += `if(${out}===${g.fail})return ${g.fail};`;\n return { code, value: out };\n}\n\n/**\n * Dispatch on the discriminator and build ONLY the option that value selects,\n * failing outright when it selects none — mirroring zod, which resolves the\n * option through a `discriminator value → option` map built from each option's\n * `propValues` and pushes `invalid_union` (\"No matching discriminator\") without\n * ever running an option's parse when the lookup misses.\n *\n * Probing the options in order like {@link buildUnion} does is NOT equivalent,\n * because an option can accept more than its own dispatch values. A wrapper that\n * substitutes a value contributes only the value it wraps to `propValues` while\n * its parse also accepts the input it substitutes FOR:\n * `z.literal(\"a\").default(\"a\")` dispatches on `\"a\"` alone yet parses a MISSING\n * discriminator, so sequential probing accepted `{v:\"x\"}` — output `{t:\"a\",v:\"x\"}`\n * — where zod rejects it. `.prefault()` and `.catch()` have the same shape, and\n * only escape it because neither reaches this pass today (a prefaulted schema\n * delegates to zod wholesale, and `.catch()` is refused by\n * {@link mutatesBeyondStrip}); a `.default()` is exactly what pulls the build\n * path in. The switch cannot drift that way: the dispatch table IS zod's, so an\n * unlisted discriminator reaches `default:` and fails, whatever the options\n * would have accepted on their own.\n *\n * The reverse — rejecting what zod accepts — is why `.optional()`/`.nullable()`\n * discriminators stay compiled rather than being refused here: their\n * `undefined`/`null` are in `propValues`, so they arrive as ordinary cases.\n *\n * Object-ness is proved BEFORE the discriminator is read, both because zod\n * rejects a non-object with its own `invalid_type` ahead of the lookup and\n * because the property read would throw on `null`/`undefined`.\n */\nfunction buildDiscriminatedUnion(\n ir: SchemaIR & { type: \"discriminatedUnion\" },\n input: string,\n g: BuildGen,\n): Built | null {\n return buildDispatch(ir.discriminator, ir.cases, ir.options, input, g);\n}\n\n/**\n * The switch behind {@link buildDiscriminatedUnion} and a dispatched\n * {@link buildUnion}: prove object-ness, select the option the discriminator\n * names, and build that option alone. Switches over the literal labels, as the\n * fast path does — see `emitFastDiscriminatedSwitch` for the measurement that\n * retired the ordinal-table form.\n */\nfunction buildDispatch(\n discriminator: string,\n cases: DiscriminatedUnionIR[\"cases\"],\n options: readonly SchemaIR[],\n input: string,\n g: BuildGen,\n): Built | null {\n const out = local(g, \"bd\");\n // One hosted build per REACHABLE option, keyed by option index: a multi-value\n // literal (`z.literal([\"a\",\"c\"])`) contributes several cases selecting the\n // same option, and they share the one function rather than emitting it twice.\n //\n // Each option is hosted with the discriminator as its skip key: the guard\n // below and the matched `case` have settled object-ness and the tag, so the\n // option's own object omits both (see BuildGen.discSkipKey, and the fast\n // path's FastGen.discSkipKey for the pass-through options).\n const hostedByOption = new Map<number, string>();\n let arms = \"\";\n for (const { value, option: index } of cases) {\n let fn = hostedByOption.get(index);\n if (fn === undefined) {\n const option = options[index];\n if (option === undefined) return null;\n const hosted = g.rebuilds.has(option)\n ? hostBuild(option, g, discriminator)\n : hostPassthrough(option, g, discriminator);\n if (hosted === null) return null;\n fn = hosted;\n hostedByOption.set(index, fn);\n }\n arms += `case ${literalToJs(value)}:${out}=${fn}(${input});break;`;\n }\n if (arms === \"\") return null;\n\n return {\n code:\n `if(typeof ${input}!==\"object\"||${input}===null||Array.isArray(${input}))return ${g.fail};` +\n `switch(${input}[${escapeString(discriminator)}]){${arms}default:return ${g.fail};}` +\n `if(${out}===${g.fail})return ${g.fail};`,\n value: out,\n };\n}\n\n/**\n * Host a non-rebuilding option as `value-or-FAIL`, so a union can probe it with\n * the same protocol as a rebuilding one.\n */\nfunction hostPassthrough(ir: SchemaIR, g: BuildGen, discSkipKey?: string): string | null {\n const param = emitTemp(g.ctx, \"bp\");\n const scope: FastScope = { temps: [], used: 0 };\n const expr = generateFast(ir, createFastGen(param, g.ctx, true, scope, discSkipKey));\n if (expr === null) return null;\n const name = emitTemp(g.ctx, \"vp\");\n g.ctx.preamble.push(\n `function ${name}(${param}){${declareFastTemps(scope)}return ${expr === \"true\" ? param : `(${expr})?${param}:${g.fail}`};}`,\n );\n return name;\n}\n\n/**\n * Validate in place with the Fast Path and hand the input straight back —\n * filtered through `__zcPs` for a container zod would have stripped an own\n * `__proto__` from (see ZC_PROTO_SCRUB_DECL). The filter copies only when the\n * key is present, so the ordinary value is still returned by reference.\n */\nfunction passthrough(ir: SchemaIR, input: string, g: BuildGen): Built | null {\n const scoped = createFastGen(input, g.ctx, true, g.scope, g.discSkipKey);\n const expr = generateFast(ir, scoped);\n if (expr === null) return null;\n const guard = expr === \"true\" ? \"\" : `if(!(${expr}))return ${g.fail};`;\n if (!needsProtoScrub(ir)) return { code: guard, value: input };\n const slot = local(g, \"bs\");\n const scrub = emitRuntimeHelper(g.ctx, \"__zcPs\", ZC_PROTO_SCRUB_DECL);\n return { code: `${guard}${slot}=${scrub}(${input});`, value: slot };\n}\n\n/**\n * Rebuild from the declared keys. Sound for a stripping object (that IS the\n * output) and for a strict one (unknown keys are rejected, so the declared keys\n * are the whole key set). A loose object or one with a `.catchall()` keeps keys\n * this pass does not enumerate, so those bail.\n */\n/**\n * Freeze the inner's built value, matching zod's `Object.freeze(payload.value)`.\n *\n * Sound only because `freeze` is set exclusively over a stripping object, whose\n * build ALWAYS allocates (`buildObject` assembles a fresh `__bo_N`) — so the\n * frozen value is never the caller's input. A pass-through inner would return\n * `input` here and freezing it would mutate data the caller still owns, which\n * is why the extractor withholds the flag for every other container.\n */\nfunction buildReadonly(\n ir: SchemaIR & { type: \"readonly\" },\n input: string,\n g: BuildGen,\n): Built | null {\n const built = build(ir.inner, input, g);\n if (built === null || ir.freeze !== true) return built;\n const slot = local(g, \"bz\");\n return { code: `${built.code}${slot}=Object.freeze(${built.value});`, value: slot };\n}\n\nfunction buildObject(ir: ObjectIR, input: string, g: BuildGen): Built | null {\n if (ir.catchall !== undefined) return null;\n if (ir.stripUnknownKeys !== true && ir.strict !== true) return null;\n // Both swallow an absent key's failure, which a single-pass build that fails\n // at the first bad check cannot model.\n if (ir.skipAbsentKeys !== undefined && ir.skipAbsentKeys.length > 0) return null;\n if (ir.suppressAbsentKeys !== undefined && ir.suppressAbsentKeys.length > 0) return null;\n const nonoptional = new Set(ir.nonoptionalKeys ?? []);\n // Object-level `.refine()` runs on the assembled output (below). superRefine\n // rewrites the payload, which this pass does not model — mutatesBeyondStrip\n // already rejects it, so this is a belt-and-braces narrowing of the type.\n const refines = ir.checks ?? [];\n if (refines.some((check) => check.kind !== \"refine_effect\")) return null;\n\n // A dispatched union option (see buildDispatch): the switch has proved\n // object-ness and matched this key's value, so neither is checked again.\n // Consumed here; the properties' own builds never see it.\n const skipKey = g.discSkipKey;\n const childGen: BuildGen = skipKey === undefined ? g : { ...g, discSkipKey: undefined };\n\n let code =\n skipKey === undefined\n ? `if(typeof ${input}!==\"object\"||${input}===null||Array.isArray(${input}))return ${g.fail};`\n : \"\";\n\n if (ir.strict === true) {\n const keyVar = local(g, \"bk\");\n code += `for(${keyVar} in ${input}){if(!(${keyMembershipTest(g.ctx, Object.keys(ir.properties), keyVar)}))return ${g.fail};}`;\n }\n\n // Properties are VALIDATED cheapest-first and ASSEMBLED in shape order (see\n // orderedForBuild): every value lands in its own local, so the order the\n // checks run in is free to differ from the order the keys are written in.\n const properties = parsedProperties(ir);\n const built = new Map<string, Built>();\n for (const [key, propIR] of orderedForBuild(properties, g.ctx)) {\n const keyStr = escapeString(key);\n const slot = local(g, \"bv\");\n if (key === skipKey && !g.rebuilds.has(propIR)) {\n // The matched tag. A pass-through property's output is its input, and\n // the switch compared exactly this value, so read it for the output\n // literal and skip its check (the fast path's discSkipKey does the same).\n // A REBUILDING tag — a transformed literal — is built as usual: only its\n // check is redundant, not its output.\n code += `${slot}=${input}[${keyStr}];`;\n built.set(key, { code: \"\", value: slot });\n continue;\n }\n // A required key has to be present whatever its schema makes of `undefined`.\n if (nonoptional.has(key)) code += `if(!(${keyStr} in ${input}))return ${g.fail};`;\n code += `${slot}=${input}[${keyStr}];`;\n const propBuilt = build(propIR, slot, childGen);\n if (propBuilt === null) return null;\n code += propBuilt.code;\n built.set(key, propBuilt);\n }\n const slots = properties.map(([key, propIR]) => ({\n always: outputAlwaysDefined(propIR),\n keyStr: escapeString(key),\n value: (built.get(key) as Built).value,\n }));\n\n // Same assembly the eager strip walk uses: the longest LEADING run of\n // always-present keys goes into one object literal (V8 stamps it from a\n // cached boilerplate map in a single allocation), and everything after the\n // first conditional key is appended so insertion order still matches zod.\n // The per-key test is zod's own — keep the key when the parsed value is\n // defined, or when it was present on the input at all.\n const out = local(g, \"bo\");\n const literal: string[] = [];\n let appends = \"\";\n let leading = true;\n for (const slot of slots) {\n if (leading && slot.always) {\n literal.push(`${slot.keyStr}:${slot.value}`);\n continue;\n }\n leading = false;\n appends += slot.always\n ? `${out}[${slot.keyStr}]=${slot.value};`\n : `if(${slot.value}!==undefined||(${slot.keyStr} in ${input})){${out}[${slot.keyStr}]=${slot.value};}`;\n }\n code += `${out}={${literal.join(\",\")}};${appends}`;\n // Zod parses the properties into the payload first and skips the check chain\n // when that produced issues, so a bad property suppresses the refine — which\n // this pass gets for free, having already returned FAIL at that property.\n for (const check of refines) {\n code += buildRefine(check as RefineEffectCheckIR, out, g);\n }\n return { code, value: out };\n}\n\n/**\n * A `.refine()` predicate on the build path: FAIL on a falsy verdict, and\n * zod's synchronous-parse error on a Promise — which is truthy, so an\n * unguarded test would accept the input (see ZC_ASYNC_DECL). The verdict is\n * bound to a local so the Promise test reads it once.\n */\nfunction buildRefine(check: RefineEffectCheckIR, value: string, g: BuildGen): string {\n const asy = emitRuntimeHelper(g.ctx, \"__zcAsy\", ZC_ASYNC_DECL);\n const verdict = local(g, \"br\");\n return `${verdict}=${emitEffectCallable(g.ctx, check)}(${value});if(${verdict} instanceof Promise)${asy}();if(!${verdict})return ${g.fail};`;\n}\n\nfunction buildArray(ir: SchemaIR & { type: \"array\" }, input: string, g: BuildGen): Built | null {\n // Length checks are pure predicates over `input.length`, so they hoist ahead\n // of the element loop: a size mismatch bails before a single element is\n // validated. Zod reports the per-element issue first when both fail, but the\n // build pass produces no issues — only the sentinel — and the deferred walk\n // that does produce them keeps zod's order.\n let sizes = \"\";\n const refines: RefineEffectCheckIR[] = [];\n for (const check of ir.checks) {\n switch (check.kind) {\n case \"min_length\":\n sizes += `if(${input}.length<${check.minimum})return ${g.fail};`;\n break;\n case \"max_length\":\n sizes += `if(${input}.length>${check.maximum})return ${g.fail};`;\n break;\n case \"length_equals\":\n sizes += `if(${input}.length!==${check.length})return ${g.fail};`;\n break;\n case \"refine_effect\":\n refines.push(check);\n break;\n default:\n // super_refine (rewrites the value) or a check kind not modelled here.\n return null;\n }\n }\n\n const out = local(g, \"ba\");\n const index = local(g, \"bi\");\n const elem = local(g, \"be\");\n const inner = build(ir.element, elem, g);\n if (inner === null) return null;\n let code =\n `if(!Array.isArray(${input}))return ${g.fail};` +\n sizes +\n `${out}=new Array(${input}.length);` +\n `for(${index}=0;${index}<${input}.length;${index}++){` +\n `${elem}=${input}[${index}];${inner.code}${out}[${index}]=${inner.value};}`;\n // `.refine()` sees the parsed payload, which for a rebuilding element is the\n // freshly assembled array — the same value zod hands its checks.\n for (const check of refines) {\n code += buildRefine(check, out, g);\n }\n return { code, value: out };\n}\n\nfunction buildTuple(ir: SchemaIR & { type: \"tuple\" }, input: string, g: BuildGen): Built | null {\n // Trailing-optional and rest handling shape the output length; keep those on\n // the eager walk rather than restating the rules here.\n if (ir.rest !== null) return null;\n if (ir.optStart !== ir.items.length) return null;\n if (ir.items.some((item) => !rejectsUndefined(item))) return null;\n\n let code = `if(!Array.isArray(${input})||${input}.length!==${ir.items.length})return ${g.fail};`;\n const values: string[] = [];\n for (const [index, itemIR] of ir.items.entries()) {\n const slot = local(g, \"bt\");\n code += `${slot}=${input}[${index}];`;\n const inner = build(itemIR as SchemaIR, slot, g);\n if (inner === null) return null;\n code += inner.code;\n values.push(inner.value);\n }\n const out = local(g, \"bl\");\n code += `${out}=[${values.join(\",\")}];`;\n return { code, value: out };\n}\n\nfunction buildRecord(ir: SchemaIR & { type: \"record\" }, input: string, g: BuildGen): Built | null {\n const plainStringKey =\n ir.keyType.type === \"string\" && ir.keyType.checks.length === 0 && ir.keyType.coerce !== true;\n if (!plainStringKey) return null;\n\n const out = local(g, \"br\");\n const keyVar = local(g, \"brk\");\n const valVar = local(g, \"brv\");\n const inner = build(ir.valueType, valVar, g);\n if (inner === null) return null;\n const hop = emitRuntimeHelper(g.ctx, \"__zcHop\", ZC_HOP_DECL);\n // `$ZodRecord` gates on `util.isPlainObject`, not the `util.isObject` the\n // object/discriminated-union builds above use — see ZC_PLAIN_DECL. And it\n // skips `__proto__` outright: here that guard is load-bearing twice over,\n // since `out[key]=value` for that key would not add a property at all but\n // REDEFINE the built object's prototype.\n const plain = emitRuntimeHelper(g.ctx, \"__zcPlain\", ZC_PLAIN_DECL);\n const code =\n `if(!${plain}(${input}))return ${g.fail};` +\n `${out}={};` +\n `for(${keyVar} in ${input}){if(${keyVar}!==\"__proto__\"&&${hop}.call(${input},${keyVar})){` +\n `${valVar}=${input}[${keyVar}];${inner.code}${out}[${keyVar}]=${inner.value};}}`;\n return { code, value: out };\n}\n\n/**\n * `.transform(fn)`: validate the inner schema, then hand its parsed value to the\n * callback. `z.preprocess(fn, schema)` reverses those two steps: call first,\n * then validate the callback's output. Returning FAIL from the inner build\n * preserves the corresponding pipe short-circuit in either direction.\n *\n * The IR reaches here only for a synchronous single-argument callback: a\n * `ctx`-taking or async transform is extracted as a `fallback` instead\n * (see extractPipe), so there is no parse context to reproduce.\n */\nfunction buildEffect(ir: SchemaIR & { type: \"effect\" }, input: string, g: BuildGen): Built | null {\n // A callback that returns a Promise is zod's synchronous-parse error, not a\n // value (see ZC_ASYNC_DECL); tested right after the call, as zod does.\n const asy = emitRuntimeHelper(g.ctx, \"__zcAsy\", ZC_ASYNC_DECL);\n if (ir.effectKind === \"preprocess\") {\n const value = local(g, \"bpv\");\n const inner = build(ir.inner, value, g);\n if (inner === null) return null;\n return {\n code: `${value}=${emitEffectCallable(g.ctx, ir)}(${input});if(${value} instanceof Promise)${asy}();${inner.code}`,\n value: inner.value,\n };\n }\n\n const inner = build(ir.inner, input, g);\n if (inner === null) return null;\n const out = local(g, \"bx\");\n return {\n code: `${inner.code}${out}=${emitEffectCallable(g.ctx, ir)}(${inner.value});if(${out} instanceof Promise)${asy}();`,\n value: out,\n };\n}\n\n/**\n * A coercing and/or overwrite string (`z.coerce.string()`, `.trim()`,\n * `.toLowerCase()`, ...): coerce first, then emit checks one statement at a time\n * in DECLARATION order, interleaved with rewrites, because a rewrite is visible\n * to every check after it — `z.string().trim().min(1)` rejects `\" \"` where\n * `z.string().min(1).trim()` accepts it. That ordering is exactly why the fast\n * path, which sorts checks cheapest-first and returns the input unchanged, has\n * to decline these.\n *\n * Only reached for a rewriting string; a non-coercing, check-only one never\n * enters the rebuild set and is validated in place by `passthrough`.\n */\nfunction buildString(ir: SchemaIR & { type: \"string\" }, input: string, g: BuildGen): Built | null {\n const value = local(g, \"bs\");\n let code =\n ir.coerce === true\n ? `try{${value}=String(${input});}catch(_){return ${g.fail};}`\n : `if(typeof ${input}!==\"string\")return ${g.fail};${value}=${input};`;\n for (const check of ir.checks) {\n switch (check.kind) {\n case \"overwrite_effect\":\n code += `${value}=${emitEffectFn(g.ctx, check.source)}(${value});`;\n break;\n case \"refine_effect\":\n code += buildRefine(check, value, g);\n break;\n case \"super_refine_effect\":\n // Rewrites through zod's payload; mutatesBeyondStrip already rejects it.\n return null;\n default: {\n const expr = fastStringCheck(check, value, g.ctx);\n if (expr === null) return null; // z.url(), unknown format\n code += `if(!(${expr}))return ${g.fail};`;\n }\n }\n }\n return { code, value };\n}\n\n/**\n * `z.stringbool()`: normalize once, select the declared truthy/falsy side, and\n * return the boolean directly. The ordinary Fast Path cannot host this codec\n * because its contract returns the original input by reference; the build path\n * is designed for exactly this kind of small output rewrite.\n *\n * Case-insensitive codecs look the input up VERBATIM before lowercasing it.\n * The accepted spellings are all lowercase (see extractStringBool), so an\n * exact hit is what `toLowerCase()` would have produced anyway, and the common\n * config flag or query parameter is spelled that way already. For the hashed\n * form that is one `Map.get` in place of `toLowerCase()` plus one. A miss\n * lowercases and looks up again — unless lowercasing changed nothing, in which\n * case the second lookup would only repeat the first, so a lowercase\n * non-spelling is rejected for the price of the old path plus one string\n * compare. Measured per value on V8: 10.8 → 7.5 ns over lowercase spellings,\n * 13.5 → 10.7 ns over a mixed-case rotation. The inline form compares the raw\n * string against its few spellings first — pointer compares on internalized\n * strings — for the same trade.\n */\nfunction buildStringBool(ir: StringBoolIR, input: string, g: BuildGen): Built {\n let code = `if(typeof ${input}!==\"string\")return ${g.fail};`;\n const out = local(g, \"bb\");\n if (stringBoolUsesInline(ir)) {\n let normalized = input;\n if (!ir.caseSensitive) {\n normalized = local(g, \"bn\");\n code += `${normalized}=${stringBoolInlineHit(ir, input)}?${input}:${input}.toLowerCase();`;\n }\n const membership = (values: readonly string[]): string =>\n values.map((value) => `${normalized}===${escapeString(value)}`).join(\"||\");\n code +=\n `if(${membership(ir.truthy)}){${out}=true;}` +\n `else if(${membership(ir.falsy)}){${out}=false;}` +\n `else{return ${g.fail};}`;\n } else {\n const lookup = emitStringBoolMap(ir, g.ctx);\n code += `${out}=${lookup}.get(${input});`;\n if (!ir.caseSensitive) {\n const lowered = local(g, \"bn\");\n code +=\n `if(${out}===undefined){${lowered}=${input}.toLowerCase();` +\n `if(${lowered}!==${input}){${out}=${lookup}.get(${lowered});}}`;\n }\n code += `if(${out}===undefined)return ${g.fail};`;\n }\n return { code, value: out };\n}\n\n/** Primitive nodes whose `coerce` flag rewrites their output before checks run. */\ntype CoercedPrimitiveIR = Extract<SchemaIR, { type: \"number\" | \"boolean\" | \"bigint\" | \"date\" }>;\n\n/**\n * Coerce once into a local, then reuse the ordinary Fast Path as the acceptance\n * predicate over the converted value. The build path only needs a verdict on\n * its hot pass; if it fails, the existing deferred slow walk reruns the original\n * coercing schema and produces Zod-identical issues.\n *\n * Number/BigInt/Date conversion can invoke user hooks and throw. Zod catches\n * those throws and reports invalid_type, so the sentinel branch does the same\n * without allocating an issue. Boolean never invokes conversion hooks.\n */\nfunction buildCoercedPrimitive(ir: CoercedPrimitiveIR, input: string, g: BuildGen): Built | null {\n if (ir.coerce !== true) return null;\n const value = local(g, \"bc\");\n let conversion: string;\n switch (ir.type) {\n case \"number\":\n conversion = `Number(${input})`;\n break;\n case \"boolean\":\n conversion = `Boolean(${input})`;\n break;\n case \"bigint\":\n conversion = `BigInt(${input})`;\n break;\n case \"date\":\n conversion = `new Date(${input})`;\n break;\n }\n\n // A fresh shallow node is intentional: only the coerce flag changes. The\n // existing primitive generator remains the single source of truth for every\n // range, format, refine and finite/valid-date check.\n const predicate = generateFast(\n { ...ir, coerce: false },\n createFastGen(value, g.ctx, true, g.scope),\n );\n if (predicate === null) return null;\n\n const assign = `${value}=${conversion};`;\n const code = ir.type === \"boolean\" ? assign : `try{${assign}}catch(_){return ${g.fail};}`;\n return {\n code: code + (predicate === \"true\" ? \"\" : `if(!(${predicate}))return ${g.fail};`),\n value,\n };\n}\n\n/**\n * `.default(v)`: `undefined` yields the declared value without running the\n * inner schema, anything else parses normally — the same two branches\n * `slowDefault` emits, reading the value off the retained schema so a\n * reference-typed default keeps zod's identity (one shared object, not a copy).\n *\n * The substituted value is not validated. The by-reference fast form refuses\n * `undefined` for that reason (it would hand the input back, not the default);\n * the acceptance form `.is()` runs accepts it, as the schema does — see\n * fastDefault.\n */\nfunction buildDefault(\n ir: SchemaIR & { type: \"default\" },\n input: string,\n g: BuildGen,\n): Built | null {\n const inner = build(ir.inner, input, g);\n if (inner === null) return null;\n const out = local(g, \"bq\");\n const value = defaultValueExpr(ir);\n // Zod re-applies the default when the inner returns undefined for a defined\n // input; only emitted when the inner can actually do that.\n const reapply = needsPostInnerDefault(ir) ? `if(${out}===undefined){${out}=${value};}` : \"\";\n return {\n code:\n `if(${input}===undefined){${out}=${value};}` +\n `else{${inner.code}${out}=${inner.value};${reapply}}`,\n value: out,\n };\n}\n\n/** `optional` / `nullable` around a rebuilding inner: pass the sentinel through. */\nfunction buildSentinel(\n innerIR: SchemaIR,\n input: string,\n g: BuildGen,\n test: string,\n sentinel: string,\n): Built | null {\n const inner = build(innerIR, input, g);\n if (inner === null) return null;\n const out = local(g, \"bw\");\n return {\n code: `if(${input}${test}){${out}=${sentinel};}else{${inner.code}${out}=${inner.value};}`,\n value: out,\n };\n}\n\n/** Allocate a `var` the hosted build function declares. */\nfunction local(g: BuildGen, prefix: string): string {\n const name = emitTemp(g.ctx, prefix);\n g.scope.temps.push(name);\n return name;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8HA,SAAS,WAAW,MAAgB,oBAAoB,MAA6B;CACnF,MAAM,0BAAU,IAAI,IAAsB,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;CACrD,MAAM,QAAoB,CAAC;CAC3B,MAAM,uBAAO,IAAI,IAAc;CAC/B,MAAM,WAAW,SAAyB;EACxC,IAAI,KAAK,IAAI,IAAI,GAAG;EACpB,KAAK,IAAI,IAAI;EACb,MAAM,KAAK,IAAI;EACf,IAAI,KAAK,SAAS,mBAAmB,QAAQ,IAAI,KAAK,OAAO,KAAK,KAAK;EACvE,KAAK,MAAM,SAAS,SAAS,IAAI,GAAG,QAAQ,KAAK;CACnD;CACA,QAAQ,IAAI;CAEZ,MAAM,2BAAW,IAAI,IAAc;CACnC,KAAK,IAAI,UAAU,MAAM,UAAU;EACjC,UAAU;EACV,KAAK,MAAM,QAAQ,OAAO;G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,UAAU,WAAW,EAAE,KAAK;EAC9E;CACF;AACF;;;;;;;;;;;;AAaA,SAAS,aACP,IACA,OACA,GACc;CACd,MAAM,QAAQ,MAAM,GAAG,OAAO,OAAO,CAAC;CACtC,IAAI,UAAU,MAAM,OAAO;CAC3B,MAAM,MAAM,MAAM,GAAG,IAAI;CACzB,MAAM,QAAQ,iBAAiB,EAAE;CAGjC,MAAM,UAAU,sBAAsB,EAAE,IAAI,MAAM,IAAI,gBAAgB,IAAI,GAAG,MAAM,MAAM;CACzF,OAAO;EACL,MACE,MAAM,MAAM,gBAAgB,IAAI,GAAG,MAAM,SACjC,MAAM,OAAO,IAAI,GAAG,MAAM,MAAM,GAAG,QAAQ;EACrD,OAAO;CACT;AACF;;AAGA,SAAS,cACP,SACA,OACA,GACA,MACA,UACc;CACd,MAAM,QAAQ,MAAM,SAAS,OAAO,CAAC;CACrC,IAAI,UAAU,MAAM,OAAO;CAC3B,MAAM,MAAM,MAAM,GAAG,IAAI;CACzB,OAAO;EACL,MAAM,MAAM,QAAQ,KAAK,IAAI,IAAI,GAAG,SAAS,SAAS,MAAM,OAAO,IAAI,GAAG,MAAM,MAAM;EACtF,OAAO;CACT;AACF;;AAGA,SAAS,MAAM,GAAa,QAAwB;CAClD,MAAM,OAAO,SAAS,EAAE,KAAK,MAAM;CACnC,EAAE,MAAM,MAAM,KAAK,IAAI;CACvB,OAAO;AACT"}
|
|
@@ -343,6 +343,15 @@ declare function emitEffectCallable(ctx: CodeGenContext, effect: {
|
|
|
343
343
|
* a cycle.
|
|
344
344
|
*/
|
|
345
345
|
declare function emitRfDelegate(ctx: CodeGenContext, refIndex: number): string;
|
|
346
|
+
/**
|
|
347
|
+
* A retained schema's `_zod` internals, aliased into the preamble for the
|
|
348
|
+
* sub-schema delegate that runs it through `_zod.run` (see
|
|
349
|
+
* ZC_RUN_DELEGATE_DECL). Bound once per IIFE like `__rfp_N`, so the per-parse
|
|
350
|
+
* call is a property load on a constant rather than an `__rf[N]` element read.
|
|
351
|
+
* Unlike `safeParse`, `_zod` is never replaced by `__zcMkv`, so here the alias
|
|
352
|
+
* is a cost saving, not a cycle guard.
|
|
353
|
+
*/
|
|
354
|
+
declare function emitRfZod(ctx: CodeGenContext, refIndex: number): string;
|
|
346
355
|
/**
|
|
347
356
|
* Identifier `generateIIFE` binds the retained Zod schema to, once per export.
|
|
348
357
|
*
|
|
@@ -568,5 +577,5 @@ declare function rejectsUndefined(ir: SchemaIR): boolean;
|
|
|
568
577
|
*/
|
|
569
578
|
declare function checkPriority(a: CheckIR | BigIntCheckIR | DateCheckIR | SetCheckIR, b: CheckIR | BigIntCheckIR | DateCheckIR | SetCheckIR): number;
|
|
570
579
|
//#endregion
|
|
571
|
-
export { CodeGenContext, CodeGenResult, CodegenMode, ConstantKind, ENUM_INLINE_THRESHOLD, FastGen, FastGenerator, FastScope, GeneratedConstant, KEY_MEMBERSHIP_INLINE_THRESHOLD, RETAINED_SCHEMA_VAR, RecTargetGen, SlowGen, SlowGenerator, SourceFormLiteral, checkPriority, declareFastTemps, emitConstant, emitEffectCallable, emitEffectFn, emitPooledConstant, emitRegex, emitRegexSourceString, emitRetainedMethod, emitRfDelegate, emitRuntimeHelper, emitSet, emitTemp, escapeString, extendPath, extendStaticPath, extendStaticPathIndex, fastSentinelWrapper, hasMutation, hasSourceForm, keyMembershipTest, literalToJs, needsProtoScrub, outputAlwaysDefined, rejectsUndefined, tupleRewritesShortInput };
|
|
580
|
+
export { CodeGenContext, CodeGenResult, CodegenMode, ConstantKind, ENUM_INLINE_THRESHOLD, FastGen, FastGenerator, FastScope, GeneratedConstant, KEY_MEMBERSHIP_INLINE_THRESHOLD, RETAINED_SCHEMA_VAR, RecTargetGen, SlowGen, SlowGenerator, SourceFormLiteral, checkPriority, declareFastTemps, emitConstant, emitEffectCallable, emitEffectFn, emitPooledConstant, emitRegex, emitRegexSourceString, emitRetainedMethod, emitRfDelegate, emitRfZod, emitRuntimeHelper, emitSet, emitTemp, escapeString, extendPath, extendStaticPath, extendStaticPathIndex, fastSentinelWrapper, hasMutation, hasSourceForm, keyMembershipTest, literalToJs, needsProtoScrub, outputAlwaysDefined, rejectsUndefined, tupleRewritesShortInput };
|
|
572
581
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","names":[],"sources":["../../../src/core/codegen/context.ts"],"mappings":";;;;KAgBY;;;;;KAMA;;;;;;;;;;;;;;;;UAiBK;WACN,MAAM;WACN;WACA;;UAGM;EACf;EACA;;EAEA;;;;;;EAMA,aAAa;;;;;;;EAOb;;;;;;;;;;EAUA;;;;;;;EAOA;;;;;;;EAOA;;;UAIe;;EAEf;;;;;EAKA;;;;;;EAMA;;EAEA,QAAQ;;;UAIO;EACf;EACA;EACA;;EAEA,YAAY;;EAEZ,MAAM;;EAEN,aAAa;;;;;;;;EAQb;;;;;;;;;EASA,aAAa,YAAY;;EAEzB,gBAAgB;;EAEhB,aAAa;;EAEb,eAAe,UAAU;;EAEzB,sBAAsB;;EAEtB;;EAEA,gBAAgB;;EAEhB,gBAAgB,QAAQ;;EAExB,uBAAuB,QAAQ;;;;;;EAM/B,gBAAgB;;;UAMD;WACN;WACA;WACA;WACA;WACA,KAAK;;;;;;;WAOL;;;;;;;;;;;;;;;;WAiBA;;;;;;;;;EAUT,MACE,IAAI,UACJ;IACE;IACA;IACA;IACA;IAGA;;;EAKJ,KAAK;;EAGL,MAAM,gBAAgB,iBAAiB;;EAGvC,IAAI,gBAAgB;;;KAIV,cAAc,UAAU,WAAW,aAAa,IAAI,GAAG,GAAG;;;;;;UASrD;EACf;;;;;;;;;;;EAWA;;;iBAIc,iBAAiB,OAAO;;;;;;;;;;;;;;;;;;;;iBAuBxB,oBACd,GAAG,SACH,SAAS,UACT,kBACA;;UAkBe;WACN;WACA,KAAK;;;;;;;WAQL;;WAGA,OAAO;;;;;;;WAQP;;;;;;;;;;;WAYA;;;;;EAMT,MAAM,IAAI,UAAU;IAAc;IAAgB;;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