zod-compiler 1.26.0 → 1.26.2
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 +40 -1
- package/dist/cli/emitter.d.ts +2 -2
- package/dist/cli/emitter.d.ts.map +1 -1
- package/dist/cli/emitter.js +3 -2
- package/dist/cli/emitter.js.map +1 -1
- package/dist/core/codegen/build-path.d.ts.map +1 -1
- package/dist/core/codegen/build-path.js +15 -6
- package/dist/core/codegen/build-path.js.map +1 -1
- package/dist/core/codegen/context.d.ts +75 -9
- package/dist/core/codegen/context.d.ts.map +1 -1
- package/dist/core/codegen/context.js +81 -7
- package/dist/core/codegen/context.js.map +1 -1
- package/dist/core/codegen/index.d.ts +6 -2
- package/dist/core/codegen/index.d.ts.map +1 -1
- package/dist/core/codegen/index.js +12 -10
- package/dist/core/codegen/index.js.map +1 -1
- package/dist/core/codegen/well-known-regex.d.ts.map +1 -1
- package/dist/core/codegen/well-known-regex.js +16 -0
- package/dist/core/codegen/well-known-regex.js.map +1 -1
- package/dist/core/iife.d.ts +33 -11
- package/dist/core/iife.d.ts.map +1 -1
- package/dist/core/iife.js +46 -15
- package/dist/core/iife.js.map +1 -1
- package/dist/core/pipeline.d.ts +9 -10
- package/dist/core/pipeline.d.ts.map +1 -1
- package/dist/core/pipeline.js +87 -17
- package/dist/core/pipeline.js.map +1 -1
- package/dist/jit.d.ts.map +1 -1
- package/dist/jit.js.map +1 -1
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.js +9 -3
- package/dist/unplugin/transform.js.map +1 -1
- package/dist/unplugin/virtual.js +1 -1
- package/package.json +2 -1
|
@@ -84,6 +84,22 @@ const WELL_KNOWN_REGEXES = [
|
|
|
84
84
|
{
|
|
85
85
|
name: "__zcReGuid",
|
|
86
86
|
source: "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: "__zcReIsoDate",
|
|
90
|
+
source: "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "__zcReIsoTime",
|
|
94
|
+
source: "^(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?$"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "__zcReIsoDateTime",
|
|
98
|
+
source: "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "__zcReIsoDuration",
|
|
102
|
+
source: "^P(?:(\\d+W)|(?!.*W)(?=\\d|T\\d)(\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+([.,]\\d+)?S)?)?)$"
|
|
87
103
|
}
|
|
88
104
|
];
|
|
89
105
|
const SOURCE_TO_NAME = new Map(WELL_KNOWN_REGEXES.map((r) => [r.source, r.name]));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"well-known-regex.js","names":[],"sources":["../../../src/core/codegen/well-known-regex.ts"],"sourcesContent":["/**\n * Well-known regex sources hosted in the virtual module \"virtual:zod-compiler/runtime\".\n *\n * In lean mode (unplugin), `g.regex()` consults this registry and emits a reference\n * like `__zcReEmail` instead of declaring `var __re_email_*=new RegExp(...)`.\n * The bundler then deduplicates the regex literal across all transformed files.\n *\n * Pattern sources are matched verbatim (string equality). Add new entries as Zod\n * exposes additional well-known formats and we want bundle-wide dedup.\n */\n\nimport { unrollRepeats } from \"./regex-unroll.js\";\n\n/** Zod v4's email regex source (string.ts uses this directly when format === \"email\"). */\nexport const EMAIL_REGEX_SOURCE = String.raw`^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$`;\n\n/**\n * Behavior-equivalent rewrite of EMAIL_REGEX_SOURCE that runs ~1.45x faster on V8.\n *\n * Zod's pattern fronts two lookaheads; `(?!.*\\.\\.)` re-scans the entire string\n * before matching starts. The rewrite encodes the same constraints structurally:\n * the local part is dot-separated runs of `[A-Za-z0-9_'+-]` (no leading dot, no\n * empty run ⇒ no `..`) ending in `[A-Za-z0-9_+-]`, and the domain grammar already\n * makes `..` impossible (every label starts with an alphanumeric).\n *\n * Equivalence is enforced by tests/core/codegen/email-fast-regex.test.ts\n * (exhaustive short-string sweep + structured cases + random fuzz).\n */\nexport const EMAIL_FAST_REGEX_SOURCE = String.raw`^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$`;\n\n/** Fallback UUID regex used when the extractor doesn't provide a pattern (e.g. in unit tests). */\nexport const UUID_REGEX_SOURCE =\n \"^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$\";\n\nexport interface WellKnownRegex {\n /** Stable virtual-module export name. Always starts with \"__zcRe\". */\n name: string;\n /** Pattern source string (verbatim match against `g.regex()` 2nd argument). */\n source: string;\n /**\n * Behavior-equivalent faster pattern used for the actual `.test()` regex.\n * Issue reporting (`pattern:` field) always uses `source` so generated\n * issues stay byte-identical to zod's.\n */\n testSource?: string;\n}\n\nexport const WELL_KNOWN_REGEXES: readonly WellKnownRegex[] = [\n { name: \"__zcReEmail\", source: EMAIL_REGEX_SOURCE, testSource: EMAIL_FAST_REGEX_SOURCE },\n { name: \"__zcReUuid\", source: UUID_REGEX_SOURCE },\n { name: \"__zcReCuid\", source: \"^[cC][^\\\\s-]{8,}$\" },\n { name: \"__zcReCuid2\", source: \"^[0-9a-z]+$\" },\n { name: \"__zcReUlid\", source: \"^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$\" },\n { name: \"__zcReNanoid\", source: \"^[a-zA-Z0-9_-]{21}$\" },\n { name: \"__zcReXid\", source: \"^[0-9a-vA-V]{20}$\" },\n { name: \"__zcReKsuid\", source: \"^[A-Za-z0-9]{27}$\" },\n {\n name: \"__zcReIpv4\",\n source:\n \"^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$\",\n },\n {\n name: \"__zcReIpv6\",\n source:\n \"^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$\",\n },\n {\n name: \"__zcReBase64\",\n source: \"^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$\",\n },\n { name: \"__zcReBase64Url\", source: \"^[A-Za-z0-9_-]*$\" },\n { name: \"__zcReE164\", source: \"^\\\\+[1-9]\\\\d{6,14}$\" },\n {\n name: \"__zcReGuid\",\n source: \"^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$\",\n },\n];\n\nconst SOURCE_TO_NAME: ReadonlyMap<string, string> = new Map(\n WELL_KNOWN_REGEXES.map((r) => [r.source, r.name]),\n);\n\nconst SOURCE_TO_TEST_SOURCE: ReadonlyMap<string, string> = new Map(\n WELL_KNOWN_REGEXES.filter((r) => r.testSource !== undefined).map((r) => [\n r.source,\n r.testSource as string,\n ]),\n);\n\n/**\n * Look up a well-known regex by its pattern source string.\n * Returns the virtual-module export name or null if the pattern is user-defined.\n */\nexport function lookupWellKnownRegex(source: string): string | null {\n return SOURCE_TO_NAME.get(source) ?? null;\n}\n\n/**\n * Look up the hand-written behavior-equivalent test pattern for a regex source.\n * Returns null when no rewrite is registered in {@link WELL_KNOWN_REGEXES}.\n *\n * This is the TABLE lookup only. Codegen calls {@link fastTestSource}, which\n * layers automatic repeat unrolling on top and also covers user-supplied\n * patterns that are in no table.\n */\nexport function lookupFastRegexSource(source: string): string | null {\n return SOURCE_TO_TEST_SOURCE.get(source) ?? null;\n}\n\n/**\n * The pattern a generated `.test()` should actually run for `source`, or null\n * when `source` is already the best form.\n *\n * Two behavior-preserving rewrites compose here: the hand-written table entry\n * above (currently just email), then {@link unrollRepeats}, which turns bounded\n * repeats of single-character atoms into explicit repetition — worth 1.3-3.4x\n * on the string formats everyday schemas use (uuid, guid, ulid, nanoid, xid,\n * ksuid, base64, e164, iso.date). Unrolling runs on the table rewrite when\n * there is one, so the two stack.\n *\n * Callers must apply this only to flag-less regexes (the flagged form would\n * need its flags carried into the reported pattern too) and must keep\n * reporting the ORIGINAL source in issues — see `emitRegexSourceString`.\n */\nexport function fastTestSource(source: string): string | null {\n const tableRewrite = SOURCE_TO_TEST_SOURCE.get(source) ?? null;\n return unrollRepeats(tableRewrite ?? source) ?? tableRewrite;\n}\n\n/**\n * Virtual-module export name for the ORIGINAL `/source/` pattern string of a\n * rewritten well-known regex (e.g. \"__zcReEmailSrc\"). Issue sites reference it\n * so the original pattern stays a single bundle-wide string even though the\n * runtime regex object is built from testSource.\n */\nexport function wellKnownRegexSourceName(source: string): string | null {\n const name = SOURCE_TO_NAME.get(source);\n if (name === undefined) return null;\n return fastTestSource(source) !== null ? `${name}Src` : null;\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAa,qBAAqB,OAAO,GAAG;;;;;;;;;;;;;AAc5C,MAAa,0BAA0B,OAAO,GAAG;;AAGjD,MAAa,oBACX;AAeF,MAAa,qBAAgD;CAC3D;EAAE,MAAM;EAAe,QAAQ;EAAoB,YAAY;CAAwB;CACvF;EAAE,MAAM;EAAc,QAAQ;CAAkB;CAChD;EAAE,MAAM;EAAc,QAAQ;CAAoB;CAClD;EAAE,MAAM;EAAe,QAAQ;CAAc;CAC7C;EAAE,MAAM;EAAc,QAAQ;CAAwC;CACtE;EAAE,MAAM;EAAgB,QAAQ;CAAsB;CACtD;EAAE,MAAM;EAAa,QAAQ;CAAoB;CACjD;EAAE,MAAM;EAAe,QAAQ;CAAoB;CACnD;EACE,MAAM;EACN,QACE;CACJ;CACA;EACE,MAAM;EACN,QACE;CACJ;CACA;EACE,MAAM;EACN,QAAQ;CACV;CACA;EAAE,MAAM;EAAmB,QAAQ;CAAmB;CACtD;EAAE,MAAM;EAAc,QAAQ;CAAsB;CACpD;EACE,MAAM;EACN,QAAQ;CACV;AACF;AAEA,MAAM,iBAA8C,IAAI,IACtD,mBAAmB,KAAK,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,CAClD;AAEA,MAAM,wBAAqD,IAAI,IAC7D,mBAAmB,QAAQ,MAAM,EAAE,eAAe,KAAA,CAAS,CAAC,CAAC,KAAK,MAAM,CACtE,EAAE,QACF,EAAE,UACJ,CAAC,CACH;;;;;AAMA,SAAgB,qBAAqB,QAA+B;CAClE,OAAO,eAAe,IAAI,MAAM,KAAK;AACvC;;;;;;;;;AAUA,SAAgB,sBAAsB,QAA+B;CACnE,OAAO,sBAAsB,IAAI,MAAM,KAAK;AAC9C;;;;;;;;;;;;;;;;AAiBA,SAAgB,eAAe,QAA+B;CAC5D,MAAM,eAAe,sBAAsB,IAAI,MAAM,KAAK;CAC1D,OAAO,cAAc,gBAAgB,MAAM,KAAK;AAClD;;;;;;;AAQA,SAAgB,yBAAyB,QAA+B;CACtE,MAAM,OAAO,eAAe,IAAI,MAAM;CACtC,IAAI,SAAS,KAAA,GAAW,OAAO;CAC/B,OAAO,eAAe,MAAM,MAAM,OAAO,GAAG,KAAK,OAAO;AAC1D"}
|
|
1
|
+
{"version":3,"file":"well-known-regex.js","names":[],"sources":["../../../src/core/codegen/well-known-regex.ts"],"sourcesContent":["/**\n * Well-known regex sources hosted in the virtual module \"virtual:zod-compiler/runtime\".\n *\n * In lean mode (unplugin), `g.regex()` consults this registry and emits a reference\n * like `__zcReEmail` instead of declaring `var __re_email_*=new RegExp(...)`.\n * The bundler then deduplicates the regex literal across all transformed files.\n *\n * Pattern sources are matched verbatim (string equality). Add new entries as Zod\n * exposes additional well-known formats and we want bundle-wide dedup.\n */\n\nimport { unrollRepeats } from \"./regex-unroll.js\";\n\n/** Zod v4's email regex source (string.ts uses this directly when format === \"email\"). */\nexport const EMAIL_REGEX_SOURCE = String.raw`^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$`;\n\n/**\n * Behavior-equivalent rewrite of EMAIL_REGEX_SOURCE that runs ~1.45x faster on V8.\n *\n * Zod's pattern fronts two lookaheads; `(?!.*\\.\\.)` re-scans the entire string\n * before matching starts. The rewrite encodes the same constraints structurally:\n * the local part is dot-separated runs of `[A-Za-z0-9_'+-]` (no leading dot, no\n * empty run ⇒ no `..`) ending in `[A-Za-z0-9_+-]`, and the domain grammar already\n * makes `..` impossible (every label starts with an alphanumeric).\n *\n * Equivalence is enforced by tests/core/codegen/email-fast-regex.test.ts\n * (exhaustive short-string sweep + structured cases + random fuzz).\n */\nexport const EMAIL_FAST_REGEX_SOURCE = String.raw`^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$`;\n\n/** Fallback UUID regex used when the extractor doesn't provide a pattern (e.g. in unit tests). */\nexport const UUID_REGEX_SOURCE =\n \"^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$\";\n\nexport interface WellKnownRegex {\n /** Stable virtual-module export name. Always starts with \"__zcRe\". */\n name: string;\n /** Pattern source string (verbatim match against `g.regex()` 2nd argument). */\n source: string;\n /**\n * Behavior-equivalent faster pattern used for the actual `.test()` regex.\n * Issue reporting (`pattern:` field) always uses `source` so generated\n * issues stay byte-identical to zod's.\n */\n testSource?: string;\n}\n\nexport const WELL_KNOWN_REGEXES: readonly WellKnownRegex[] = [\n { name: \"__zcReEmail\", source: EMAIL_REGEX_SOURCE, testSource: EMAIL_FAST_REGEX_SOURCE },\n { name: \"__zcReUuid\", source: UUID_REGEX_SOURCE },\n { name: \"__zcReCuid\", source: \"^[cC][^\\\\s-]{8,}$\" },\n { name: \"__zcReCuid2\", source: \"^[0-9a-z]+$\" },\n { name: \"__zcReUlid\", source: \"^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$\" },\n { name: \"__zcReNanoid\", source: \"^[a-zA-Z0-9_-]{21}$\" },\n { name: \"__zcReXid\", source: \"^[0-9a-vA-V]{20}$\" },\n { name: \"__zcReKsuid\", source: \"^[A-Za-z0-9]{27}$\" },\n {\n name: \"__zcReIpv4\",\n source:\n \"^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$\",\n },\n {\n name: \"__zcReIpv6\",\n source:\n \"^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$\",\n },\n {\n name: \"__zcReBase64\",\n source: \"^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$\",\n },\n { name: \"__zcReBase64Url\", source: \"^[A-Za-z0-9_-]*$\" },\n { name: \"__zcReE164\", source: \"^\\\\+[1-9]\\\\d{6,14}$\" },\n {\n name: \"__zcReGuid\",\n source: \"^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$\",\n },\n // The ISO family. Zod BUILDS these from the call's options, so only the\n // default spelling is a fixed string — `z.iso.datetime({ offset: true })` or\n // `{ precision: 3 }` produces a different source that simply misses this\n // exact-match table and keeps its per-IIFE declaration. Defaults are worth\n // listing anyway: `z.iso.datetime()` is everywhere in API schemas and its\n // pattern is ~330 characters, so a bundle that repeats it per validator pays\n // for it in bytes and in a RegExp construction per schema at module init.\n {\n name: \"__zcReIsoDate\",\n source:\n \"^(?:(?:\\\\d\\\\d[2468][048]|\\\\d\\\\d[13579][26]|\\\\d\\\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\\\d|30)|(?:02)-(?:0[1-9]|1\\\\d|2[0-8])))$\",\n },\n { name: \"__zcReIsoTime\", source: \"^(?:[01]\\\\d|2[0-3]):[0-5]\\\\d(?::[0-5]\\\\d(?:\\\\.\\\\d+)?)?$\" },\n {\n name: \"__zcReIsoDateTime\",\n source:\n \"^(?:(?:\\\\d\\\\d[2468][048]|\\\\d\\\\d[13579][26]|\\\\d\\\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\\\d|30)|(?:02)-(?:0[1-9]|1\\\\d|2[0-8])))T(?:(?:[01]\\\\d|2[0-3]):[0-5]\\\\d(?::[0-5]\\\\d(?:\\\\.\\\\d+)?)?(?:Z))$\",\n },\n {\n name: \"__zcReIsoDuration\",\n source:\n \"^P(?:(\\\\d+W)|(?!.*W)(?=\\\\d|T\\\\d)(\\\\d+Y)?(\\\\d+M)?(\\\\d+D)?(T(?=\\\\d)(\\\\d+H)?(\\\\d+M)?(\\\\d+([.,]\\\\d+)?S)?)?)$\",\n },\n];\n\nconst SOURCE_TO_NAME: ReadonlyMap<string, string> = new Map(\n WELL_KNOWN_REGEXES.map((r) => [r.source, r.name]),\n);\n\nconst SOURCE_TO_TEST_SOURCE: ReadonlyMap<string, string> = new Map(\n WELL_KNOWN_REGEXES.filter((r) => r.testSource !== undefined).map((r) => [\n r.source,\n r.testSource as string,\n ]),\n);\n\n/**\n * Look up a well-known regex by its pattern source string.\n * Returns the virtual-module export name or null if the pattern is user-defined.\n */\nexport function lookupWellKnownRegex(source: string): string | null {\n return SOURCE_TO_NAME.get(source) ?? null;\n}\n\n/**\n * Look up the hand-written behavior-equivalent test pattern for a regex source.\n * Returns null when no rewrite is registered in {@link WELL_KNOWN_REGEXES}.\n *\n * This is the TABLE lookup only. Codegen calls {@link fastTestSource}, which\n * layers automatic repeat unrolling on top and also covers user-supplied\n * patterns that are in no table.\n */\nexport function lookupFastRegexSource(source: string): string | null {\n return SOURCE_TO_TEST_SOURCE.get(source) ?? null;\n}\n\n/**\n * The pattern a generated `.test()` should actually run for `source`, or null\n * when `source` is already the best form.\n *\n * Two behavior-preserving rewrites compose here: the hand-written table entry\n * above (currently just email), then {@link unrollRepeats}, which turns bounded\n * repeats of single-character atoms into explicit repetition — worth 1.3-3.4x\n * on the string formats everyday schemas use (uuid, guid, ulid, nanoid, xid,\n * ksuid, base64, e164, iso.date). Unrolling runs on the table rewrite when\n * there is one, so the two stack.\n *\n * Callers must apply this only to flag-less regexes (the flagged form would\n * need its flags carried into the reported pattern too) and must keep\n * reporting the ORIGINAL source in issues — see `emitRegexSourceString`.\n */\nexport function fastTestSource(source: string): string | null {\n const tableRewrite = SOURCE_TO_TEST_SOURCE.get(source) ?? null;\n return unrollRepeats(tableRewrite ?? source) ?? tableRewrite;\n}\n\n/**\n * Virtual-module export name for the ORIGINAL `/source/` pattern string of a\n * rewritten well-known regex (e.g. \"__zcReEmailSrc\"). Issue sites reference it\n * so the original pattern stays a single bundle-wide string even though the\n * runtime regex object is built from testSource.\n */\nexport function wellKnownRegexSourceName(source: string): string | null {\n const name = SOURCE_TO_NAME.get(source);\n if (name === undefined) return null;\n return fastTestSource(source) !== null ? `${name}Src` : null;\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAa,qBAAqB,OAAO,GAAG;;;;;;;;;;;;;AAc5C,MAAa,0BAA0B,OAAO,GAAG;;AAGjD,MAAa,oBACX;AAeF,MAAa,qBAAgD;CAC3D;EAAE,MAAM;EAAe,QAAQ;EAAoB,YAAY;CAAwB;CACvF;EAAE,MAAM;EAAc,QAAQ;CAAkB;CAChD;EAAE,MAAM;EAAc,QAAQ;CAAoB;CAClD;EAAE,MAAM;EAAe,QAAQ;CAAc;CAC7C;EAAE,MAAM;EAAc,QAAQ;CAAwC;CACtE;EAAE,MAAM;EAAgB,QAAQ;CAAsB;CACtD;EAAE,MAAM;EAAa,QAAQ;CAAoB;CACjD;EAAE,MAAM;EAAe,QAAQ;CAAoB;CACnD;EACE,MAAM;EACN,QACE;CACJ;CACA;EACE,MAAM;EACN,QACE;CACJ;CACA;EACE,MAAM;EACN,QAAQ;CACV;CACA;EAAE,MAAM;EAAmB,QAAQ;CAAmB;CACtD;EAAE,MAAM;EAAc,QAAQ;CAAsB;CACpD;EACE,MAAM;EACN,QAAQ;CACV;CAQA;EACE,MAAM;EACN,QACE;CACJ;CACA;EAAE,MAAM;EAAiB,QAAQ;CAA0D;CAC3F;EACE,MAAM;EACN,QACE;CACJ;CACA;EACE,MAAM;EACN,QACE;CACJ;AACF;AAEA,MAAM,iBAA8C,IAAI,IACtD,mBAAmB,KAAK,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,CAClD;AAEA,MAAM,wBAAqD,IAAI,IAC7D,mBAAmB,QAAQ,MAAM,EAAE,eAAe,KAAA,CAAS,CAAC,CAAC,KAAK,MAAM,CACtE,EAAE,QACF,EAAE,UACJ,CAAC,CACH;;;;;AAMA,SAAgB,qBAAqB,QAA+B;CAClE,OAAO,eAAe,IAAI,MAAM,KAAK;AACvC;;;;;;;;;AAUA,SAAgB,sBAAsB,QAA+B;CACnE,OAAO,sBAAsB,IAAI,MAAM,KAAK;AAC9C;;;;;;;;;;;;;;;;AAiBA,SAAgB,eAAe,QAA+B;CAC5D,MAAM,eAAe,sBAAsB,IAAI,MAAM,KAAK;CAC1D,OAAO,cAAc,gBAAgB,MAAM,KAAK;AAClD;;;;;;;AAQA,SAAgB,yBAAyB,QAA+B;CACtE,MAAM,OAAO,eAAe,IAAI,MAAM;CACtC,IAAI,SAAS,KAAA,GAAW,OAAO;CAC/B,OAAO,eAAe,MAAM,MAAM,OAAO,GAAG,KAAK,OAAO;AAC1D"}
|
package/dist/core/iife.d.ts
CHANGED
|
@@ -101,10 +101,13 @@ declare const FIN_DEFERRED_DECL = "function __zcFinD(f,inp){return new __ZcFail(
|
|
|
101
101
|
* path is produced by the retained Zod schema itself (`zod` is the source of
|
|
102
102
|
* truth, so the issues are byte-identical — no second validation engine).
|
|
103
103
|
*
|
|
104
|
-
* `_z` is the schema's PRISTINE
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
104
|
+
* `_z` is the schema's PRISTINE safeParse method, captured by
|
|
105
|
+
* emitRetainedMethod (see context.ts), and `_r` is its receiver — the `__zs`
|
|
106
|
+
* binding generateIIFE places above that capture. Both are read before the
|
|
107
|
+
* trailing `__zcMkv` call installs anything, so the method is zod's own
|
|
108
|
+
* implementation, never the compiled delegate, avoiding infinite recursion
|
|
109
|
+
* without allocating a bound function. The zod parse is deferred until `.error`
|
|
110
|
+
* is read and cached, so
|
|
108
111
|
* the common `safeParse(x).success`/`.is(x)` checks on invalid input cost only
|
|
109
112
|
* the fast check (zod never runs) — the same deferral boundary `__zcFinD`
|
|
110
113
|
* establishes for the compiled slow walk. Sound because compact mode is gated
|
|
@@ -116,8 +119,8 @@ declare const FIN_DEFERRED_DECL = "function __zcFinD(f,inp){return new __ZcFail(
|
|
|
116
119
|
* the unaltered schema would have produced.
|
|
117
120
|
*/
|
|
118
121
|
declare const FAILZ_CLASS_DECL: string;
|
|
119
|
-
/** Compact-mode finalizer:
|
|
120
|
-
declare const FINZ_DECL = "function __zcFinZ(z,i){return new __ZcFailZ(z,i);}";
|
|
122
|
+
/** Compact-mode finalizer: retain a pristine safeParse, its receiver, and input lazily. */
|
|
123
|
+
declare const FINZ_DECL = "function __zcFinZ(z,r,i){return new __ZcFailZ(z,r,i);}";
|
|
121
124
|
/**
|
|
122
125
|
* Validator factory. Inline mode (CLI emitter) declares it once per compiled
|
|
123
126
|
* file; lean mode (all unplugin bundlers) exports it once per bundle from the
|
|
@@ -179,12 +182,31 @@ declare const FINZ_DECL = "function __zcFinZ(z,i){return new __ZcFailZ(z,i);}";
|
|
|
179
182
|
* 271.7 ns against the compiled 26.6 ns on the same schema, i.e. Standard Schema
|
|
180
183
|
* consumers (tRPC, Hono, TanStack) were getting plain Zod.
|
|
181
184
|
*
|
|
182
|
-
* Zod's own
|
|
183
|
-
*
|
|
185
|
+
* Zod's own `~standard` is never READ, only overwritten. Zod installs the slot
|
|
186
|
+
* with `util.defineLazy` — commented there as "avoid creating objects for every
|
|
187
|
+
* schema" — so it is an accessor that builds `{version, vendor, validate}` plus
|
|
188
|
+
* its closure on first touch. Reading it to capture a fallback fired that getter
|
|
189
|
+
* for every compiled schema while the module was still initializing.
|
|
190
|
+
*
|
|
191
|
+
* How much that costs depends on the entry point, and only one of them is free:
|
|
192
|
+
* classic `zod` forces the slot itself during `ZodType.init` (it does
|
|
193
|
+
* `Object.assign(inst["~standard"], { jsonSchema })`), so there the read hit an
|
|
194
|
+
* already-built object and cost only an accessor call. `zod/mini` and raw
|
|
195
|
+
* `zod/v4/core` never touch it, so for those the read built — and retained — an
|
|
196
|
+
* object and a closure per schema, purely to capture a fallback the schema will
|
|
197
|
+
* most likely never expose to a Standard Schema consumer.
|
|
198
|
+
*
|
|
199
|
+
* The throw path is rebuilt instead of captured. Zod's validate catches a
|
|
200
|
+
* synchronous throw and retries through `safeParseAsync` — that is how an async
|
|
184
201
|
* refinement resolves and how a throwing check surfaces as a rejected promise
|
|
185
|
-
* rather than a synchronous throw
|
|
186
|
-
*
|
|
187
|
-
*
|
|
202
|
+
* rather than a synchronous throw — so calling the already-captured `zspa` and
|
|
203
|
+
* mapping its result is the same route to the same result. `vendor` is likewise
|
|
204
|
+
* a constant: schema discovery only ever admits zod schemas, and classic, mini
|
|
205
|
+
* and core all hardcode `vendor: "zod"` themselves.
|
|
206
|
+
*
|
|
207
|
+
* Not carried over (unchanged by this, and pre-dating it): classic's
|
|
208
|
+
* `~standard.jsonSchema` extension, which the replacement object has never
|
|
209
|
+
* reproduced.
|
|
188
210
|
*
|
|
189
211
|
* Installed with defineProperty rather than assignment: Zod's lazy setter
|
|
190
212
|
* redefines the slot as non-writable, so a second `__zcMkv` on the same schema
|
package/dist/core/iife.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iife.d.ts","names":[],"sources":["../../src/core/iife.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"iife.d.ts","names":[],"sources":["../../src/core/iife.ts"],"mappings":";;;;;;;;cAca;;;;;;;;;;;;;;;;;;;;cAsBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8CA;;;cAUA;;;;;;;;;;;;;;;;;;;;;;;cAyBA;;;;;;;;;;;;;;;;;;;;;;;;;;cA2BA;;cAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6FA;;;;;;;;;iBAqBG,aACd,oBACA,QAAQ,oBACR;EAAY"}
|
package/dist/core/iife.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { RETAINED_SCHEMA_VAR } from "./codegen/context.js";
|
|
1
2
|
//#region src/core/iife.ts
|
|
2
3
|
/**
|
|
4
|
+
* Shared CompiledSchema<T> IIFE generation.
|
|
5
|
+
* Used by both CLI emitter and unplugin transform.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
3
8
|
* Import statement required by generateIIFE output (references
|
|
4
9
|
* __zodCompilerConfig). `core` is bound for $ZodAsyncError: superRefine and
|
|
5
10
|
* custom callbacks may only reveal that they are async through the promise
|
|
@@ -100,10 +105,13 @@ const FIN_DEFERRED_DECL = "function __zcFinD(f,inp){return new __ZcFail(null,f,i
|
|
|
100
105
|
* path is produced by the retained Zod schema itself (`zod` is the source of
|
|
101
106
|
* truth, so the issues are byte-identical — no second validation engine).
|
|
102
107
|
*
|
|
103
|
-
* `_z` is the schema's PRISTINE
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
108
|
+
* `_z` is the schema's PRISTINE safeParse method, captured by
|
|
109
|
+
* emitRetainedMethod (see context.ts), and `_r` is its receiver — the `__zs`
|
|
110
|
+
* binding generateIIFE places above that capture. Both are read before the
|
|
111
|
+
* trailing `__zcMkv` call installs anything, so the method is zod's own
|
|
112
|
+
* implementation, never the compiled delegate, avoiding infinite recursion
|
|
113
|
+
* without allocating a bound function. The zod parse is deferred until `.error`
|
|
114
|
+
* is read and cached, so
|
|
107
115
|
* the common `safeParse(x).success`/`.is(x)` checks on invalid input cost only
|
|
108
116
|
* the fast check (zod never runs) — the same deferral boundary `__zcFinD`
|
|
109
117
|
* establishes for the compiled slow walk. Sound because compact mode is gated
|
|
@@ -114,9 +122,9 @@ const FIN_DEFERRED_DECL = "function __zcFinD(f,inp){return new __ZcFail(null,f,i
|
|
|
114
122
|
* re-wrap — zod already finalized it), so a delegated failure is exactly what
|
|
115
123
|
* the unaltered schema would have produced.
|
|
116
124
|
*/
|
|
117
|
-
const FAILZ_CLASS_DECL = "function __ZcFailZ(z,i){this.success=false;this._z=z;this._i=i;this._c=undefined;}Object.defineProperty(__ZcFailZ.prototype,\"error\",{configurable:true,get:function(){return this._c||(this._c=this._z(this._i).error);}});";
|
|
118
|
-
/** Compact-mode finalizer:
|
|
119
|
-
const FINZ_DECL = "function __zcFinZ(z,i){return new __ZcFailZ(z,i);}";
|
|
125
|
+
const FAILZ_CLASS_DECL = "function __ZcFailZ(z,r,i){this.success=false;this._z=z;this._r=r;this._i=i;this._c=undefined;}Object.defineProperty(__ZcFailZ.prototype,\"error\",{configurable:true,get:function(){return this._c||(this._c=this._z.call(this._r,this._i).error);}});";
|
|
126
|
+
/** Compact-mode finalizer: retain a pristine safeParse, its receiver, and input lazily. */
|
|
127
|
+
const FINZ_DECL = "function __zcFinZ(z,r,i){return new __ZcFailZ(z,r,i);}";
|
|
120
128
|
/**
|
|
121
129
|
* Validator factory. Inline mode (CLI emitter) declares it once per compiled
|
|
122
130
|
* file; lean mode (all unplugin bundlers) exports it once per bundle from the
|
|
@@ -178,18 +186,37 @@ const FINZ_DECL = "function __zcFinZ(z,i){return new __ZcFailZ(z,i);}";
|
|
|
178
186
|
* 271.7 ns against the compiled 26.6 ns on the same schema, i.e. Standard Schema
|
|
179
187
|
* consumers (tRPC, Hono, TanStack) were getting plain Zod.
|
|
180
188
|
*
|
|
181
|
-
* Zod's own
|
|
182
|
-
*
|
|
189
|
+
* Zod's own `~standard` is never READ, only overwritten. Zod installs the slot
|
|
190
|
+
* with `util.defineLazy` — commented there as "avoid creating objects for every
|
|
191
|
+
* schema" — so it is an accessor that builds `{version, vendor, validate}` plus
|
|
192
|
+
* its closure on first touch. Reading it to capture a fallback fired that getter
|
|
193
|
+
* for every compiled schema while the module was still initializing.
|
|
194
|
+
*
|
|
195
|
+
* How much that costs depends on the entry point, and only one of them is free:
|
|
196
|
+
* classic `zod` forces the slot itself during `ZodType.init` (it does
|
|
197
|
+
* `Object.assign(inst["~standard"], { jsonSchema })`), so there the read hit an
|
|
198
|
+
* already-built object and cost only an accessor call. `zod/mini` and raw
|
|
199
|
+
* `zod/v4/core` never touch it, so for those the read built — and retained — an
|
|
200
|
+
* object and a closure per schema, purely to capture a fallback the schema will
|
|
201
|
+
* most likely never expose to a Standard Schema consumer.
|
|
202
|
+
*
|
|
203
|
+
* The throw path is rebuilt instead of captured. Zod's validate catches a
|
|
204
|
+
* synchronous throw and retries through `safeParseAsync` — that is how an async
|
|
183
205
|
* refinement resolves and how a throwing check surfaces as a rejected promise
|
|
184
|
-
* rather than a synchronous throw
|
|
185
|
-
*
|
|
186
|
-
*
|
|
206
|
+
* rather than a synchronous throw — so calling the already-captured `zspa` and
|
|
207
|
+
* mapping its result is the same route to the same result. `vendor` is likewise
|
|
208
|
+
* a constant: schema discovery only ever admits zod schemas, and classic, mini
|
|
209
|
+
* and core all hardcode `vendor: "zod"` themselves.
|
|
210
|
+
*
|
|
211
|
+
* Not carried over (unchanged by this, and pre-dating it): classic's
|
|
212
|
+
* `~standard.jsonSchema` extension, which the replacement object has never
|
|
213
|
+
* reproduced.
|
|
187
214
|
*
|
|
188
215
|
* Installed with defineProperty rather than assignment: Zod's lazy setter
|
|
189
216
|
* redefines the slot as non-writable, so a second `__zcMkv` on the same schema
|
|
190
217
|
* object — two exports aliasing one schema — would throw under ESM strict mode.
|
|
191
218
|
*/
|
|
192
|
-
const MK_VALIDATOR_DECL = "function __zcMkv(fn,schema,fc,is){var w=schema||{};var zpa=w.parseAsync,zspa=w.safeParseAsync;w.parse=fc?function(input){if(fc(input))return input;var r=fn(input);if(r.success)return r.data;throw r.error;}:function(input){var r=fn(input);if(r.success)return r.data;throw r.error;};w.safeParse=fn;w.safeParseAsync=function(input){try{return Promise.resolve(fn(input));}catch(e){if(zspa)return zspa(input);throw e;}};w.parseAsync=fc?function(input){try{if(fc(input))return Promise.resolve(input);var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);}catch(e){if(zpa)return zpa(input);throw e;}}:function(input){try{var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);}catch(e){if(zpa)return zpa(input);throw e;}};w.is=is||function(input){return fn(input).success;};
|
|
219
|
+
const MK_VALIDATOR_DECL = "function __zcMkv(fn,schema,fc,is){var w=schema||{};var zpa=w.parseAsync,zspa=w.safeParseAsync;w.parse=fc?function(input){if(fc(input))return input;var r=fn(input);if(r.success)return r.data;throw r.error;}:function(input){var r=fn(input);if(r.success)return r.data;throw r.error;};w.safeParse=fn;w.safeParseAsync=function(input){try{return Promise.resolve(fn(input));}catch(e){if(zspa)return zspa(input);throw e;}};w.parseAsync=fc?function(input){try{if(fc(input))return Promise.resolve(input);var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);}catch(e){if(zpa)return zpa(input);throw e;}}:function(input){try{var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);}catch(e){if(zpa)return zpa(input);throw e;}};w.is=is||function(input){return fn(input).success;};Object.defineProperty(w,\"~standard\",{configurable:true,value:{version:1,vendor:\"zod\",validate:function(input){var r;try{if(fc&&fc(input))return{value:input};r=fn(input);}catch(e){if(zspa)return zspa(input).then(function(q){return q.success?{value:q.data}:{issues:q.error.issues};});throw e;}return r.success?{value:r.data}:{issues:r.error.issues};}}});return w;}";
|
|
193
220
|
function extractFunctionName(functionDef) {
|
|
194
221
|
const match = /^function\s+(\w+)\s*\(/.exec(functionDef);
|
|
195
222
|
if (!match?.[1]) throw new Error("Cannot extract function name from generated code");
|
|
@@ -206,12 +233,16 @@ function extractFunctionName(functionDef) {
|
|
|
206
233
|
function generateIIFE(schemaExpr, schema, options) {
|
|
207
234
|
const { codegenResult, refEntries } = schema;
|
|
208
235
|
const fnName = extractFunctionName(codegenResult.functionDef);
|
|
209
|
-
const
|
|
236
|
+
const zodCompat = options?.zodCompat !== false;
|
|
237
|
+
const bindsSchema = refEntries.length > 0 || codegenResult.usesRetainedSchema === true;
|
|
238
|
+
const retainedSchema = bindsSchema ? RETAINED_SCHEMA_VAR : schemaExpr;
|
|
239
|
+
const schemaArg = zodCompat ? retainedSchema : "null";
|
|
210
240
|
const fcArg = codegenResult.fastFnName ?? "null";
|
|
211
241
|
const isArg = codegenResult.isFnName ?? (codegenResult.fastTotal ? fcArg : "null");
|
|
212
242
|
return [
|
|
213
243
|
"/* @__PURE__ */ (() => {",
|
|
214
|
-
...
|
|
244
|
+
...bindsSchema ? [`var ${RETAINED_SCHEMA_VAR}=${schemaExpr};`] : [],
|
|
245
|
+
...refEntries.length > 0 ? [`var __rf=[${refEntries.map((fb) => `${retainedSchema}${fb.accessPath}`).join(",")}];`] : [],
|
|
215
246
|
...codegenResult.code.split("\n").filter((l) => l.trim() !== "" && l.trim() !== "/* zod-compiler */"),
|
|
216
247
|
codegenResult.functionDef,
|
|
217
248
|
`return __zcMkv(${fnName},${schemaArg},${fcArg},${isArg});`,
|
package/dist/core/iife.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iife.js","names":[],"sources":["../../src/core/iife.ts"],"sourcesContent":["/**\n * Shared CompiledSchema<T> IIFE generation.\n * Used by both CLI emitter and unplugin transform.\n */\n\nimport type { CompiledSchemaInfo } from \"./pipeline.js\";\n\n/**\n * Import statement required by generateIIFE output (references\n * __zodCompilerConfig). `core` is bound for $ZodAsyncError: superRefine and\n * custom callbacks may only reveal that they are async through the promise\n * they return, at which point zod's own synchronous parse raises.\n */\nexport const ZOD_CONFIG_IMPORT =\n 'import { config as __zodCompilerConfig, core as __zcCore, ZodRealError as __zcZodError } from \"zod\";';\n\n/**\n * File-level `__zcMsg` declaration (must appear once after ZOD_CONFIG_IMPORT):\n * the message an issue gets when nothing was baked into it at build time.\n *\n * Resolves zod's tail of `finalizeIssue` — `config.customError` then\n * `config.localeError` then \"Invalid input\" — and does it PER CALL, because the\n * config is mutable: `z.config({ localeError })` in an entry point runs after\n * the schema modules it imports, so a value snapshotted at module init misses\n * it. Reading a captured `localeError` alone also dropped `customError`\n * outright, silently ignoring the global map most i18n setups install.\n *\n * The head of zod's chain — the schema's own `error` option — is baked into the\n * issue at build time and short-circuits this. The one link that cannot be\n * reproduced is a per-CALL `ctx.error`, which would have to travel through\n * `safeParse`; that entry point sits at V8's inlining budget, where even an\n * unused extra parameter measured ~12% on every parse.\n *\n * Only ever called while building an error, never on a successful parse.\n */\nexport const ZOD_MSG_DECLARATION =\n 'function __zcUw(m){return typeof m===\"string\"?m:(m===undefined||m===null?undefined:m.message);}' +\n \"var __zcMsg=function(iss){var c=__zodCompilerConfig(),m;\" +\n \"if(c.customError){m=__zcUw(c.customError(iss));if(m!==undefined&&m!==null)return m;}\" +\n \"if(c.localeError){m=__zcUw(c.localeError(iss));if(m!==undefined&&m!==null)return m;}\" +\n 'return \"Invalid input\";};';\n\n/**\n * Shared failure-result for __zcFin / __zcFinD. Inline mode (CLI emitter)\n * declares it once per compiled file; lean mode (all unplugin bundlers) declares\n * it once per bundle in the plugin-materialized runtime module (module-local —\n * generated code only ever references __zcFin/__zcFinD, never __ZcFail).\n *\n * Why a prototype getter and not `{success:false, get error(){...}}`: an object\n * literal with an inline accessor forces V8 down its slow accessor-defining\n * allocation path — ~110ns per failure, measured — which dominates the entire\n * invalid-input cost whenever callers never read `.error`. Hosting `error` on\n * the prototype turns each failure into a plain field-only instantiation (~2ns,\n * ~13x), with the lazy-cache semantics intact. (Trade-off: `error` is a\n * prototype accessor, so it no longer shows up in `Object.keys(result)` / spread\n * / JSON.stringify of the result wrapper — `.success`/`.error`/`.data` access,\n * destructuring, and `in` are unaffected.)\n *\n * One class serves both finalizers, so the instances share one hidden class:\n * __zcFin passes pre-collected issues in `_e` (with `_f===null`); __zcFinD\n * passes the hosted slow-walk in `_f` plus the input in `_i`, and the getter\n * runs the walk on first `.error` read. The whole finalization — locale fill\n * (__zcMsg applied ONLY when an issue carries no message, never overwriting a\n * baked-in custom/fallback message), input strip, and ZodError construction\n * (zod v4 JSON.stringifies every issue into `message` and captures a stack\n * trace) — stays deferred inside the cached accessor exactly as before, since\n * the issues array is observable solely through `.error`.\n *\n * `input` is `delete`d, not assigned `undefined`. Key PRESENCE is observable —\n * `\"input\" in issue`, `Object.keys(issue)`, object spread, `toStrictEqual`\n * against a zod issue — and zod's `util.finalizeIssue` does `delete full.input`\n * whenever `reportInput` is off, so assignment left every compiled issue one\n * enumerable key wider than zod's. The delete's dictionary-mode transition is\n * affordable precisely BECAUSE of the deferral above: it runs only after a\n * caller asks for `.error` on a failed parse, and is memoised in `_c`. Neither\n * a successful parse nor a `.success`/`.is()` check on a rejected one reaches\n * it — measured, the two are unchanged, while the `.error` read itself goes\n * ~3.95us -> ~4.19us per failure, i.e. ~6% of a path whose cost is already\n * dominated by the ZodError construction on the next line (stack capture plus a\n * JSON.stringify of every issue).\n */\nexport const FAIL_CLASS_DECL =\n \"function __ZcFail(e,f,i){this.success=false;this._e=e;this._f=f;this._i=i;this._c=undefined;}\" +\n 'Object.defineProperty(__ZcFail.prototype,\"error\",{configurable:true,get:function(){' +\n \"if(this._c)return this._c;\" +\n \"var e=this._f!==null?this._f(this._i):this._e;\" +\n 'for(var i=0;i<e.length;i++){if(e[i].message===undefined&&typeof __zcMsg===\"function\")e[i].message=__zcMsg(e[i]);delete e[i].input;delete e[i].continue;}' +\n \"return this._c=new __zcZodError(e);}});\";\n\n/** Eager finalizer (mutation / partial-fast-path schemas): issues already\n * collected in `e`; success short-circuits to a plain result literal. */\nexport const FIN_DECL =\n \"function __zcFin(e,d){if(!e.length)return{success:true,data:d};return new __ZcFail(e,null,null);}\";\n\n/**\n * Deferred-collection finalizer for Fast-Path-eligible schemas. When the\n * fast check fails, the ENTIRE slow path (the issue-collecting re-walk) is\n * pushed into the cached `.error` accessor instead of running eagerly:\n * fast-eligible schemas never mutate, so the walk's only output is the\n * issues array, which is observable solely through `.error` — one step\n * further along the same lazy boundary `__zcFin` already established (locale\n * fill, input strip, ZodError construction). A failed safeParse whose\n * `.error` is never read costs the fast check alone.\n *\n * Takes the schema's HOSTED slow-walk function plus the input — NOT a\n * per-call closure: `__zcFinD(__sw_N, input)` allocates only the result\n * object, where `__zcFinD(function(){...})` paid a closure environment and\n * function object per failure. Hosting the walk also shrinks safeParse to\n * two statements, within V8's inlining budget (the success-path result\n * literal becomes escape-analyzable at monomorphic call sites).\n *\n * The walk re-reads `input` at `.error`-read time; a caller that mutates\n * the input between safeParse and reading `.error` sees issues for the\n * mutated value (zod materializes at parse time). Same caveat class as the\n * documented __zcFin deferral.\n */\nexport const FIN_DEFERRED_DECL = \"function __zcFinD(f,inp){return new __ZcFail(null,f,inp);}\";\n\n/**\n * Compact-mode failure class — a lazy failure that delegates error reporting to\n * the ORIGINAL Zod schema's `safeParse`. Used by `output: \"compact\"`, where the\n * compiled slow walk is dropped entirely: a mutation-free schema's fast check\n * is the only generated validation, and on a fast-check failure the cold error\n * path is produced by the retained Zod schema itself (`zod` is the source of\n * truth, so the issues are byte-identical — no second validation engine).\n *\n * `_z` is the schema's PRISTINE bound safeParse (`__rf[N].safeParse.bind(...)`,\n * captured pre-`__zcMkv` by emitRfDelegate — see context.ts — so it is zod's\n * own implementation, never the compiled delegate, avoiding infinite\n * recursion). The zod parse is deferred until `.error` is read and cached, so\n * the common `safeParse(x).success`/`.is(x)` checks on invalid input cost only\n * the fast check (zod never runs) — the same deferral boundary `__zcFinD`\n * establishes for the compiled slow walk. Sound because compact mode is gated\n * on a TOTAL fast path: `fc(input) === false` ⟹ zod rejects, so `success:false`\n * holds without consulting zod.\n *\n * The getter returns zod's OWN ZodError verbatim (no locale fill / input strip /\n * re-wrap — zod already finalized it), so a delegated failure is exactly what\n * the unaltered schema would have produced.\n */\nexport const FAILZ_CLASS_DECL =\n \"function __ZcFailZ(z,i){this.success=false;this._z=z;this._i=i;this._c=undefined;}\" +\n 'Object.defineProperty(__ZcFailZ.prototype,\"error\",{configurable:true,get:function(){' +\n \"return this._c||(this._c=this._z(this._i).error);}});\";\n\n/** Compact-mode finalizer: wrap a pristine bound safeParse + input into a lazy delegated failure. */\nexport const FINZ_DECL = \"function __zcFinZ(z,i){return new __ZcFailZ(z,i);}\";\n\n/**\n * Validator factory. Inline mode (CLI emitter) declares it once per compiled\n * file; lean mode (all unplugin bundlers) exports it once per bundle from the\n * plugin-materialized runtime module — generated code never imports it from\n * the zod-compiler package itself, so zod-compiler stays a devDependency and\n * the helper set is always version-locked to the codegen that calls it.\n * Wraps a safeParse function into the CompiledSchema interface.\n *\n * IDENTITY-PRESERVING: with zodCompat (schema != null) the compiled\n * parse/safeParse/parseAsync/safeParseAsync are installed as OWN properties\n * on the original schema object, which is returned as-is. zod v4 keys\n * several APIs on object identity — toJSONSchema's ctx.seen registers the\n * object it is handed while each processor closure captures the original\n * inst (a wrapper crashes `optionalProcessor` with \"Cannot set properties\n * of undefined (setting 'ref')\" the moment a compiled schema is composed\n * into another schema), and globalRegistry/.meta() is a WeakMap keyed by\n * the schema instance (a wrapper silently loses OpenAPI titles/ids). An\n * Object.create wrapper breaks both; mutating the original breaks neither\n * (zod's internal parsing flows through _zod.run, never the public\n * methods, and derived schemas — .optional(), .extend() — are fresh\n * instances that fall back to plain zod). schema=null (zodCompat: false)\n * still produces a plain method-bag object.\n *\n * fc is the schema's hosted fast-check boolean function (null when no Fast\n * Path exists). parse()/parseAsync() try it first and return the input\n * directly on success: fc is small enough for V8 to inline, so the hot parse\n * path runs with zero allocations — calling fn would allocate an intermediate\n * SafeParseResult that escape analysis cannot remove (fn never inlines).\n * Fast-path-eligible schemas never mutate, so fc(input) ⟹ data === input.\n *\n * is is the TOTAL fast-check predicate (fc when the fast path is total, else\n * null). Installed as `.is()` — a zero-allocation boolean type guard. When\n * null (partial fast path or none) `.is()` derives from fn(input).success: a\n * partial fc can pass-through valid input but its `false` does not imply\n * rejection (a default/catch may still succeed), so it would be unsound as a\n * standalone guard.\n *\n * parseAsync/safeParseAsync wrap the SYNC validator, which is right for every\n * schema the compiler can reproduce — none of them are async. It is wrong for\n * the ones it cannot: an `async` refinement or a `z.promise()` extracts to a\n * Zod delegate, and delegating means calling Zod's SYNCHRONOUS safeParse, which\n * raises `$ZodAsyncError` by design. Wrapping that gave the compiled schema an\n * async pair that rejected with `$ZodAsyncError` for EVERY input — including\n * valid ones — where Zod resolves normally, so `await UserSchema.parseAsync(x)`\n * stopped working the moment any part of the schema went async.\n *\n * So both are guarded: a synchronous throw hands off to the schema's ORIGINAL\n * async method, captured before these are installed — the same escape hatch\n * `~standard` already uses for its throw path, and for the same reason (the\n * compiled validator has no async mode to offer, and Zod's is exact). It also\n * fixes the smaller wart that a throwing `fn` made `parseAsync` throw\n * SYNCHRONOUSLY rather than return a rejected promise. With `zodCompat: false`\n * there is no schema to delegate to and the throw propagates as before.\n *\n * `~standard` is REPLACED, not merely preserved. Zod builds it lazily as\n * `validate: (v) => safeParse(inst, v)` — the core FUNCTION, which goes straight\n * to `inst._zod.run`. It never reads the schema's own `safeParse` property, so\n * installing the compiled one leaves this route entirely uncompiled: measured\n * 271.7 ns against the compiled 26.6 ns on the same schema, i.e. Standard Schema\n * consumers (tRPC, Hono, TanStack) were getting plain Zod.\n *\n * Zod's own validate is captured first and kept as the throw path: it catches a\n * synchronous throw and retries through `safeParseAsync`, which is how an async\n * refinement resolves and how a throwing check surfaces as a rejected promise\n * rather than a synchronous throw. The compiled validator cannot reproduce that\n * (async schemas delegate to Zod anyway), so deferring to the original is both\n * simpler and exact.\n *\n * Installed with defineProperty rather than assignment: Zod's lazy setter\n * redefines the slot as non-writable, so a second `__zcMkv` on the same schema\n * object — two exports aliasing one schema — would throw under ESM strict mode.\n */\nexport const MK_VALIDATOR_DECL =\n \"function __zcMkv(fn,schema,fc,is){var w=schema||{};var zpa=w.parseAsync,zspa=w.safeParseAsync;w.parse=fc?function(input){if(fc(input))return input;var r=fn(input);if(r.success)return r.data;throw r.error;}:function(input){var r=fn(input);if(r.success)return r.data;throw r.error;};w.safeParse=fn;w.safeParseAsync=function(input){try{return Promise.resolve(fn(input));}catch(e){if(zspa)return zspa(input);throw e;}};w.parseAsync=fc?function(input){try{if(fc(input))return Promise.resolve(input);var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);}catch(e){if(zpa)return zpa(input);throw e;}}:function(input){try{var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);}catch(e){if(zpa)return zpa(input);throw e;}};w.is=is||function(input){return fn(input).success;};\" +\n 'var s=w[\"~standard\"],zv=s&&s.validate;' +\n 'Object.defineProperty(w,\"~standard\",{configurable:true,value:{version:1,vendor:(s&&s.vendor)||\"zod\",validate:function(input){var r;try{if(fc&&fc(input))return{value:input};r=fn(input);}catch(e){if(zv)return zv(input);throw e;}return r.success?{value:r.data}:{issues:r.error.issues};}}});' +\n \"return w;}\";\n\nfunction extractFunctionName(functionDef: string): string {\n const match = /^function\\s+(\\w+)\\s*\\(/.exec(functionDef);\n if (!match?.[1]) {\n throw new Error(\"Cannot extract function name from generated code\");\n }\n return match[1];\n}\n\n/**\n * Generate a `/* @__PURE__ * /` IIFE wrapping a compiled validator.\n *\n * @param schemaExpr - Expression resolving to the original Zod schema\n * (e.g. `\"UserSchema\"` in unplugin, `\"(__src_X as any).schema\"` in CLI)\n * @param schema\n * @param options\n */\nexport function generateIIFE(\n schemaExpr: string,\n schema: CompiledSchemaInfo,\n options?: { zodCompat?: boolean | undefined },\n): string {\n const { codegenResult, refEntries } = schema;\n const fnName = extractFunctionName(codegenResult.functionDef);\n const zodCompat = options?.zodCompat !== false;\n const schemaArg = zodCompat ? schemaExpr : \"null\";\n const fcArg = codegenResult.fastFnName ?? \"null\";\n // `.is()` gets the fast-check directly only when it is a total predicate;\n // partial/none falls back to safeParse().success inside __zcMkv. A rebuilding\n // schema has no by-reference `fc` but still names its predicate separately.\n const isArg = codegenResult.isFnName ?? (codegenResult.fastTotal ? fcArg : \"null\");\n\n return [\n \"/* @__PURE__ */ (() => {\",\n ...(refEntries.length > 0\n ? [`var __rf=[${refEntries.map((fb) => `${schemaExpr}${fb.accessPath}`).join(\",\")}];`]\n : []),\n ...codegenResult.code\n .split(\"\\n\")\n .filter((l) => l.trim() !== \"\" && l.trim() !== \"/* zod-compiler */\"),\n codegenResult.functionDef,\n `return __zcMkv(${fnName},${schemaArg},${fcArg},${isArg});`,\n \"})()\",\n ].join(\"\\n\");\n}\n"],"mappings":";;;;;;;AAaA,MAAa,oBACX;;;;;;;;;;;;;;;;;;;;AAqBF,MAAa,sBACX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CF,MAAa,kBACX;;;AASF,MAAa,WACX;;;;;;;;;;;;;;;;;;;;;;;AAwBF,MAAa,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;AAwBjC,MAAa,mBACX;;AAKF,MAAa,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EzB,MAAa,oBACX;AAKF,SAAS,oBAAoB,aAA6B;CACxD,MAAM,QAAQ,yBAAyB,KAAK,WAAW;CACvD,IAAI,CAAC,QAAQ,IACX,MAAM,IAAI,MAAM,kDAAkD;CAEpE,OAAO,MAAM;AACf;;;;;;;;;AAUA,SAAgB,aACd,YACA,QACA,SACQ;CACR,MAAM,EAAE,eAAe,eAAe;CACtC,MAAM,SAAS,oBAAoB,cAAc,WAAW;CAE5D,MAAM,YADY,SAAS,cAAc,QACX,aAAa;CAC3C,MAAM,QAAQ,cAAc,cAAc;CAI1C,MAAM,QAAQ,cAAc,aAAa,cAAc,YAAY,QAAQ;CAE3E,OAAO;EACL;EACA,GAAI,WAAW,SAAS,IACpB,CAAC,aAAa,WAAW,KAAK,OAAO,GAAG,aAAa,GAAG,YAAY,CAAC,CAAC,KAAK,GAAG,EAAE,GAAG,IACnF,CAAC;EACL,GAAG,cAAc,KACd,MAAM,IAAI,CAAC,CACX,QAAQ,MAAM,EAAE,KAAK,MAAM,MAAM,EAAE,KAAK,MAAM,oBAAoB;EACrE,cAAc;EACd,kBAAkB,OAAO,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM;EACxD;CACF,CAAC,CAAC,KAAK,IAAI;AACb"}
|
|
1
|
+
{"version":3,"file":"iife.js","names":[],"sources":["../../src/core/iife.ts"],"sourcesContent":["/**\n * Shared CompiledSchema<T> IIFE generation.\n * Used by both CLI emitter and unplugin transform.\n */\n\nimport { RETAINED_SCHEMA_VAR } from \"./codegen/context.js\";\nimport type { CompiledSchemaInfo } from \"./pipeline.js\";\n\n/**\n * Import statement required by generateIIFE output (references\n * __zodCompilerConfig). `core` is bound for $ZodAsyncError: superRefine and\n * custom callbacks may only reveal that they are async through the promise\n * they return, at which point zod's own synchronous parse raises.\n */\nexport const ZOD_CONFIG_IMPORT =\n 'import { config as __zodCompilerConfig, core as __zcCore, ZodRealError as __zcZodError } from \"zod\";';\n\n/**\n * File-level `__zcMsg` declaration (must appear once after ZOD_CONFIG_IMPORT):\n * the message an issue gets when nothing was baked into it at build time.\n *\n * Resolves zod's tail of `finalizeIssue` — `config.customError` then\n * `config.localeError` then \"Invalid input\" — and does it PER CALL, because the\n * config is mutable: `z.config({ localeError })` in an entry point runs after\n * the schema modules it imports, so a value snapshotted at module init misses\n * it. Reading a captured `localeError` alone also dropped `customError`\n * outright, silently ignoring the global map most i18n setups install.\n *\n * The head of zod's chain — the schema's own `error` option — is baked into the\n * issue at build time and short-circuits this. The one link that cannot be\n * reproduced is a per-CALL `ctx.error`, which would have to travel through\n * `safeParse`; that entry point sits at V8's inlining budget, where even an\n * unused extra parameter measured ~12% on every parse.\n *\n * Only ever called while building an error, never on a successful parse.\n */\nexport const ZOD_MSG_DECLARATION =\n 'function __zcUw(m){return typeof m===\"string\"?m:(m===undefined||m===null?undefined:m.message);}' +\n \"var __zcMsg=function(iss){var c=__zodCompilerConfig(),m;\" +\n \"if(c.customError){m=__zcUw(c.customError(iss));if(m!==undefined&&m!==null)return m;}\" +\n \"if(c.localeError){m=__zcUw(c.localeError(iss));if(m!==undefined&&m!==null)return m;}\" +\n 'return \"Invalid input\";};';\n\n/**\n * Shared failure-result for __zcFin / __zcFinD. Inline mode (CLI emitter)\n * declares it once per compiled file; lean mode (all unplugin bundlers) declares\n * it once per bundle in the plugin-materialized runtime module (module-local —\n * generated code only ever references __zcFin/__zcFinD, never __ZcFail).\n *\n * Why a prototype getter and not `{success:false, get error(){...}}`: an object\n * literal with an inline accessor forces V8 down its slow accessor-defining\n * allocation path — ~110ns per failure, measured — which dominates the entire\n * invalid-input cost whenever callers never read `.error`. Hosting `error` on\n * the prototype turns each failure into a plain field-only instantiation (~2ns,\n * ~13x), with the lazy-cache semantics intact. (Trade-off: `error` is a\n * prototype accessor, so it no longer shows up in `Object.keys(result)` / spread\n * / JSON.stringify of the result wrapper — `.success`/`.error`/`.data` access,\n * destructuring, and `in` are unaffected.)\n *\n * One class serves both finalizers, so the instances share one hidden class:\n * __zcFin passes pre-collected issues in `_e` (with `_f===null`); __zcFinD\n * passes the hosted slow-walk in `_f` plus the input in `_i`, and the getter\n * runs the walk on first `.error` read. The whole finalization — locale fill\n * (__zcMsg applied ONLY when an issue carries no message, never overwriting a\n * baked-in custom/fallback message), input strip, and ZodError construction\n * (zod v4 JSON.stringifies every issue into `message` and captures a stack\n * trace) — stays deferred inside the cached accessor exactly as before, since\n * the issues array is observable solely through `.error`.\n *\n * `input` is `delete`d, not assigned `undefined`. Key PRESENCE is observable —\n * `\"input\" in issue`, `Object.keys(issue)`, object spread, `toStrictEqual`\n * against a zod issue — and zod's `util.finalizeIssue` does `delete full.input`\n * whenever `reportInput` is off, so assignment left every compiled issue one\n * enumerable key wider than zod's. The delete's dictionary-mode transition is\n * affordable precisely BECAUSE of the deferral above: it runs only after a\n * caller asks for `.error` on a failed parse, and is memoised in `_c`. Neither\n * a successful parse nor a `.success`/`.is()` check on a rejected one reaches\n * it — measured, the two are unchanged, while the `.error` read itself goes\n * ~3.95us -> ~4.19us per failure, i.e. ~6% of a path whose cost is already\n * dominated by the ZodError construction on the next line (stack capture plus a\n * JSON.stringify of every issue).\n */\nexport const FAIL_CLASS_DECL =\n \"function __ZcFail(e,f,i){this.success=false;this._e=e;this._f=f;this._i=i;this._c=undefined;}\" +\n 'Object.defineProperty(__ZcFail.prototype,\"error\",{configurable:true,get:function(){' +\n \"if(this._c)return this._c;\" +\n \"var e=this._f!==null?this._f(this._i):this._e;\" +\n 'for(var i=0;i<e.length;i++){if(e[i].message===undefined&&typeof __zcMsg===\"function\")e[i].message=__zcMsg(e[i]);delete e[i].input;delete e[i].continue;}' +\n \"return this._c=new __zcZodError(e);}});\";\n\n/** Eager finalizer (mutation / partial-fast-path schemas): issues already\n * collected in `e`; success short-circuits to a plain result literal. */\nexport const FIN_DECL =\n \"function __zcFin(e,d){if(!e.length)return{success:true,data:d};return new __ZcFail(e,null,null);}\";\n\n/**\n * Deferred-collection finalizer for Fast-Path-eligible schemas. When the\n * fast check fails, the ENTIRE slow path (the issue-collecting re-walk) is\n * pushed into the cached `.error` accessor instead of running eagerly:\n * fast-eligible schemas never mutate, so the walk's only output is the\n * issues array, which is observable solely through `.error` — one step\n * further along the same lazy boundary `__zcFin` already established (locale\n * fill, input strip, ZodError construction). A failed safeParse whose\n * `.error` is never read costs the fast check alone.\n *\n * Takes the schema's HOSTED slow-walk function plus the input — NOT a\n * per-call closure: `__zcFinD(__sw_N, input)` allocates only the result\n * object, where `__zcFinD(function(){...})` paid a closure environment and\n * function object per failure. Hosting the walk also shrinks safeParse to\n * two statements, within V8's inlining budget (the success-path result\n * literal becomes escape-analyzable at monomorphic call sites).\n *\n * The walk re-reads `input` at `.error`-read time; a caller that mutates\n * the input between safeParse and reading `.error` sees issues for the\n * mutated value (zod materializes at parse time). Same caveat class as the\n * documented __zcFin deferral.\n */\nexport const FIN_DEFERRED_DECL = \"function __zcFinD(f,inp){return new __ZcFail(null,f,inp);}\";\n\n/**\n * Compact-mode failure class — a lazy failure that delegates error reporting to\n * the ORIGINAL Zod schema's `safeParse`. Used by `output: \"compact\"`, where the\n * compiled slow walk is dropped entirely: a mutation-free schema's fast check\n * is the only generated validation, and on a fast-check failure the cold error\n * path is produced by the retained Zod schema itself (`zod` is the source of\n * truth, so the issues are byte-identical — no second validation engine).\n *\n * `_z` is the schema's PRISTINE safeParse method, captured by\n * emitRetainedMethod (see context.ts), and `_r` is its receiver — the `__zs`\n * binding generateIIFE places above that capture. Both are read before the\n * trailing `__zcMkv` call installs anything, so the method is zod's own\n * implementation, never the compiled delegate, avoiding infinite recursion\n * without allocating a bound function. The zod parse is deferred until `.error`\n * is read and cached, so\n * the common `safeParse(x).success`/`.is(x)` checks on invalid input cost only\n * the fast check (zod never runs) — the same deferral boundary `__zcFinD`\n * establishes for the compiled slow walk. Sound because compact mode is gated\n * on a TOTAL fast path: `fc(input) === false` ⟹ zod rejects, so `success:false`\n * holds without consulting zod.\n *\n * The getter returns zod's OWN ZodError verbatim (no locale fill / input strip /\n * re-wrap — zod already finalized it), so a delegated failure is exactly what\n * the unaltered schema would have produced.\n */\nexport const FAILZ_CLASS_DECL =\n \"function __ZcFailZ(z,r,i){this.success=false;this._z=z;this._r=r;this._i=i;this._c=undefined;}\" +\n 'Object.defineProperty(__ZcFailZ.prototype,\"error\",{configurable:true,get:function(){' +\n \"return this._c||(this._c=this._z.call(this._r,this._i).error);}});\";\n\n/** Compact-mode finalizer: retain a pristine safeParse, its receiver, and input lazily. */\nexport const FINZ_DECL = \"function __zcFinZ(z,r,i){return new __ZcFailZ(z,r,i);}\";\n\n/**\n * Validator factory. Inline mode (CLI emitter) declares it once per compiled\n * file; lean mode (all unplugin bundlers) exports it once per bundle from the\n * plugin-materialized runtime module — generated code never imports it from\n * the zod-compiler package itself, so zod-compiler stays a devDependency and\n * the helper set is always version-locked to the codegen that calls it.\n * Wraps a safeParse function into the CompiledSchema interface.\n *\n * IDENTITY-PRESERVING: with zodCompat (schema != null) the compiled\n * parse/safeParse/parseAsync/safeParseAsync are installed as OWN properties\n * on the original schema object, which is returned as-is. zod v4 keys\n * several APIs on object identity — toJSONSchema's ctx.seen registers the\n * object it is handed while each processor closure captures the original\n * inst (a wrapper crashes `optionalProcessor` with \"Cannot set properties\n * of undefined (setting 'ref')\" the moment a compiled schema is composed\n * into another schema), and globalRegistry/.meta() is a WeakMap keyed by\n * the schema instance (a wrapper silently loses OpenAPI titles/ids). An\n * Object.create wrapper breaks both; mutating the original breaks neither\n * (zod's internal parsing flows through _zod.run, never the public\n * methods, and derived schemas — .optional(), .extend() — are fresh\n * instances that fall back to plain zod). schema=null (zodCompat: false)\n * still produces a plain method-bag object.\n *\n * fc is the schema's hosted fast-check boolean function (null when no Fast\n * Path exists). parse()/parseAsync() try it first and return the input\n * directly on success: fc is small enough for V8 to inline, so the hot parse\n * path runs with zero allocations — calling fn would allocate an intermediate\n * SafeParseResult that escape analysis cannot remove (fn never inlines).\n * Fast-path-eligible schemas never mutate, so fc(input) ⟹ data === input.\n *\n * is is the TOTAL fast-check predicate (fc when the fast path is total, else\n * null). Installed as `.is()` — a zero-allocation boolean type guard. When\n * null (partial fast path or none) `.is()` derives from fn(input).success: a\n * partial fc can pass-through valid input but its `false` does not imply\n * rejection (a default/catch may still succeed), so it would be unsound as a\n * standalone guard.\n *\n * parseAsync/safeParseAsync wrap the SYNC validator, which is right for every\n * schema the compiler can reproduce — none of them are async. It is wrong for\n * the ones it cannot: an `async` refinement or a `z.promise()` extracts to a\n * Zod delegate, and delegating means calling Zod's SYNCHRONOUS safeParse, which\n * raises `$ZodAsyncError` by design. Wrapping that gave the compiled schema an\n * async pair that rejected with `$ZodAsyncError` for EVERY input — including\n * valid ones — where Zod resolves normally, so `await UserSchema.parseAsync(x)`\n * stopped working the moment any part of the schema went async.\n *\n * So both are guarded: a synchronous throw hands off to the schema's ORIGINAL\n * async method, captured before these are installed — the same escape hatch\n * `~standard` already uses for its throw path, and for the same reason (the\n * compiled validator has no async mode to offer, and Zod's is exact). It also\n * fixes the smaller wart that a throwing `fn` made `parseAsync` throw\n * SYNCHRONOUSLY rather than return a rejected promise. With `zodCompat: false`\n * there is no schema to delegate to and the throw propagates as before.\n *\n * `~standard` is REPLACED, not merely preserved. Zod builds it lazily as\n * `validate: (v) => safeParse(inst, v)` — the core FUNCTION, which goes straight\n * to `inst._zod.run`. It never reads the schema's own `safeParse` property, so\n * installing the compiled one leaves this route entirely uncompiled: measured\n * 271.7 ns against the compiled 26.6 ns on the same schema, i.e. Standard Schema\n * consumers (tRPC, Hono, TanStack) were getting plain Zod.\n *\n * Zod's own `~standard` is never READ, only overwritten. Zod installs the slot\n * with `util.defineLazy` — commented there as \"avoid creating objects for every\n * schema\" — so it is an accessor that builds `{version, vendor, validate}` plus\n * its closure on first touch. Reading it to capture a fallback fired that getter\n * for every compiled schema while the module was still initializing.\n *\n * How much that costs depends on the entry point, and only one of them is free:\n * classic `zod` forces the slot itself during `ZodType.init` (it does\n * `Object.assign(inst[\"~standard\"], { jsonSchema })`), so there the read hit an\n * already-built object and cost only an accessor call. `zod/mini` and raw\n * `zod/v4/core` never touch it, so for those the read built — and retained — an\n * object and a closure per schema, purely to capture a fallback the schema will\n * most likely never expose to a Standard Schema consumer.\n *\n * The throw path is rebuilt instead of captured. Zod's validate catches a\n * synchronous throw and retries through `safeParseAsync` — that is how an async\n * refinement resolves and how a throwing check surfaces as a rejected promise\n * rather than a synchronous throw — so calling the already-captured `zspa` and\n * mapping its result is the same route to the same result. `vendor` is likewise\n * a constant: schema discovery only ever admits zod schemas, and classic, mini\n * and core all hardcode `vendor: \"zod\"` themselves.\n *\n * Not carried over (unchanged by this, and pre-dating it): classic's\n * `~standard.jsonSchema` extension, which the replacement object has never\n * reproduced.\n *\n * Installed with defineProperty rather than assignment: Zod's lazy setter\n * redefines the slot as non-writable, so a second `__zcMkv` on the same schema\n * object — two exports aliasing one schema — would throw under ESM strict mode.\n */\nexport const MK_VALIDATOR_DECL =\n \"function __zcMkv(fn,schema,fc,is){var w=schema||{};var zpa=w.parseAsync,zspa=w.safeParseAsync;w.parse=fc?function(input){if(fc(input))return input;var r=fn(input);if(r.success)return r.data;throw r.error;}:function(input){var r=fn(input);if(r.success)return r.data;throw r.error;};w.safeParse=fn;w.safeParseAsync=function(input){try{return Promise.resolve(fn(input));}catch(e){if(zspa)return zspa(input);throw e;}};w.parseAsync=fc?function(input){try{if(fc(input))return Promise.resolve(input);var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);}catch(e){if(zpa)return zpa(input);throw e;}}:function(input){try{var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);}catch(e){if(zpa)return zpa(input);throw e;}};w.is=is||function(input){return fn(input).success;};\" +\n 'Object.defineProperty(w,\"~standard\",{configurable:true,value:{version:1,vendor:\"zod\",validate:function(input){var r;try{if(fc&&fc(input))return{value:input};r=fn(input);}catch(e){if(zspa)return zspa(input).then(function(q){return q.success?{value:q.data}:{issues:q.error.issues};});throw e;}return r.success?{value:r.data}:{issues:r.error.issues};}}});' +\n \"return w;}\";\n\nfunction extractFunctionName(functionDef: string): string {\n const match = /^function\\s+(\\w+)\\s*\\(/.exec(functionDef);\n if (!match?.[1]) {\n throw new Error(\"Cannot extract function name from generated code\");\n }\n return match[1];\n}\n\n/**\n * Generate a `/* @__PURE__ * /` IIFE wrapping a compiled validator.\n *\n * @param schemaExpr - Expression resolving to the original Zod schema\n * (e.g. `\"UserSchema\"` in unplugin, `\"(__src_X as any).schema\"` in CLI)\n * @param schema\n * @param options\n */\nexport function generateIIFE(\n schemaExpr: string,\n schema: CompiledSchemaInfo,\n options?: { zodCompat?: boolean | undefined },\n): string {\n const { codegenResult, refEntries } = schema;\n const fnName = extractFunctionName(codegenResult.functionDef);\n const zodCompat = options?.zodCompat !== false;\n // Every fallback access starts from the same source schema, and compact\n // delegation names it outright. Capture it once whenever either needs it, so\n // an inline initializer is not reconstructed for each path and again for the\n // identity-preserving __zcMkv target.\n const bindsSchema = refEntries.length > 0 || codegenResult.usesRetainedSchema === true;\n const retainedSchema = bindsSchema ? RETAINED_SCHEMA_VAR : schemaExpr;\n const schemaArg = zodCompat ? retainedSchema : \"null\";\n const fcArg = codegenResult.fastFnName ?? \"null\";\n // `.is()` gets the fast-check directly only when it is a total predicate;\n // partial/none falls back to safeParse().success inside __zcMkv. A rebuilding\n // schema has no by-reference `fc` but still names its predicate separately.\n const isArg = codegenResult.isFnName ?? (codegenResult.fastTotal ? fcArg : \"null\");\n\n return [\n \"/* @__PURE__ */ (() => {\",\n ...(bindsSchema ? [`var ${RETAINED_SCHEMA_VAR}=${schemaExpr};`] : []),\n // Only fallback refs need the array; a compact validator with none of its\n // own reads `__zs` directly rather than allocating `[__zs]` to index into.\n ...(refEntries.length > 0\n ? [`var __rf=[${refEntries.map((fb) => `${retainedSchema}${fb.accessPath}`).join(\",\")}];`]\n : []),\n ...codegenResult.code\n .split(\"\\n\")\n .filter((l) => l.trim() !== \"\" && l.trim() !== \"/* zod-compiler */\"),\n codegenResult.functionDef,\n `return __zcMkv(${fnName},${schemaArg},${fcArg},${isArg});`,\n \"})()\",\n ].join(\"\\n\");\n}\n"],"mappings":";;;;;;;;;;;;AAcA,MAAa,oBACX;;;;;;;;;;;;;;;;;;;;AAqBF,MAAa,sBACX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CF,MAAa,kBACX;;;AASF,MAAa,WACX;;;;;;;;;;;;;;;;;;;;;;;AAwBF,MAAa,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BjC,MAAa,mBACX;;AAKF,MAAa,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FzB,MAAa,oBACX;AAIF,SAAS,oBAAoB,aAA6B;CACxD,MAAM,QAAQ,yBAAyB,KAAK,WAAW;CACvD,IAAI,CAAC,QAAQ,IACX,MAAM,IAAI,MAAM,kDAAkD;CAEpE,OAAO,MAAM;AACf;;;;;;;;;AAUA,SAAgB,aACd,YACA,QACA,SACQ;CACR,MAAM,EAAE,eAAe,eAAe;CACtC,MAAM,SAAS,oBAAoB,cAAc,WAAW;CAC5D,MAAM,YAAY,SAAS,cAAc;CAKzC,MAAM,cAAc,WAAW,SAAS,KAAK,cAAc,uBAAuB;CAClF,MAAM,iBAAiB,cAAc,sBAAsB;CAC3D,MAAM,YAAY,YAAY,iBAAiB;CAC/C,MAAM,QAAQ,cAAc,cAAc;CAI1C,MAAM,QAAQ,cAAc,aAAa,cAAc,YAAY,QAAQ;CAE3E,OAAO;EACL;EACA,GAAI,cAAc,CAAC,OAAO,oBAAoB,GAAG,WAAW,EAAE,IAAI,CAAC;EAGnE,GAAI,WAAW,SAAS,IACpB,CAAC,aAAa,WAAW,KAAK,OAAO,GAAG,iBAAiB,GAAG,YAAY,CAAC,CAAC,KAAK,GAAG,EAAE,GAAG,IACvF,CAAC;EACL,GAAG,cAAc,KACd,MAAM,IAAI,CAAC,CACX,QAAQ,MAAM,EAAE,KAAK,MAAM,MAAM,EAAE,KAAK,MAAM,oBAAoB;EACrE,cAAc;EACd,kBAAkB,OAAO,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM;EACxD;CACF,CAAC,CAAC,KAAK,IAAI;AACb"}
|
package/dist/core/pipeline.d.ts
CHANGED
|
@@ -8,9 +8,9 @@ interface CompiledSchemaInfo {
|
|
|
8
8
|
codegenResult: CodeGenResult;
|
|
9
9
|
refEntries: RefEntry[];
|
|
10
10
|
}
|
|
11
|
-
/** Module-scope
|
|
11
|
+
/** Module-scope declarations produced by file-level schema and constant dedup. */
|
|
12
12
|
interface SharedSchemaBlock {
|
|
13
|
-
/** Shared `__zcSw_N` functions
|
|
13
|
+
/** Shared constants and `__zcSw_N` functions. Empty string when nothing repeats. */
|
|
14
14
|
code: string;
|
|
15
15
|
/** Runtime helper names referenced by the shared block (lean mode imports). */
|
|
16
16
|
usedHelpers: Set<string>;
|
|
@@ -27,8 +27,8 @@ interface CompileSchemasOptions {
|
|
|
27
27
|
* Compact output (`output: "compact"`). Drop the compiled slow walk for
|
|
28
28
|
* mutation-free, total-fast-path schemas and delegate their cold error path
|
|
29
29
|
* to the retained Zod schema. Disables slow-walk sharing (delegated schemas
|
|
30
|
-
* never emit a walk to share)
|
|
31
|
-
*
|
|
30
|
+
* never emit a walk to share); delegated validators read the retained schema
|
|
31
|
+
* through the `__zs` binding rather than through `__rf[]`.
|
|
32
32
|
*/
|
|
33
33
|
compact?: boolean | undefined;
|
|
34
34
|
/** When provided, per-schema failures call this and continue. Otherwise the first error throws. */
|
|
@@ -38,12 +38,11 @@ interface CompileSchemasOptions {
|
|
|
38
38
|
* Run the extract → generate pipeline for each discovered schema.
|
|
39
39
|
* Shared by CLI generate and unplugin transform.
|
|
40
40
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* to single-pass codegen (the plan is empty), paying only one linear analysis.
|
|
41
|
+
* Pass 1 extracts every schema's IR and plans repeated slow walks. Pass 2
|
|
42
|
+
* generates each validator, calling shared `__zcSw_N` functions instead of
|
|
43
|
+
* re-inlining them. Exact constant initializers reported during generation are
|
|
44
|
+
* then pooled when at least two validators use them. Files with no repetition
|
|
45
|
+
* keep their original local declarations.
|
|
47
46
|
*/
|
|
48
47
|
declare function compileSchemas(schemas: DiscoveredSchema[], options: CompileSchemasOptions): CompileSchemasResult;
|
|
49
48
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.d.ts","names":[],"sources":["../../src/core/pipeline.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","names":[],"sources":["../../src/core/pipeline.ts"],"mappings":";;;;;UAaiB;EACf;EACA,eAAe;EACf,YAAY;;;UAIG;;EAEf;;EAEA,aAAa;;;UAIE;EACf,SAAS;EACT,QAAQ;;UAGO;;EAEf,MAAM;;;;;;;;EAQN;;EAEA,WAAW,oBAAoB,OAAO;;;;;;;;;;;;iBA4FxB,eACd,SAAS,oBACT,SAAS,wBACR;;;;;iBAwHa,qBAAqB,SAAS,uBAAuB"}
|
package/dist/core/pipeline.js
CHANGED
|
@@ -1,17 +1,64 @@
|
|
|
1
|
-
import { createSharedSchemaPlan } from "./codegen/dedupe.js";
|
|
1
|
+
import { SHARED_BLOCK_MARKER, createSharedSchemaPlan } from "./codegen/dedupe.js";
|
|
2
2
|
import { generateValidator } from "./codegen/index.js";
|
|
3
3
|
import { extractSchema } from "./extract/index.js";
|
|
4
4
|
//#region src/core/pipeline.ts
|
|
5
5
|
/**
|
|
6
|
+
* Occurrences of a generated identifier in `source`, ignoring the longer names
|
|
7
|
+
* it is a prefix of — every generated name ends in `_<digits>`, so `__set_ks_1`
|
|
8
|
+
* would otherwise count itself inside `__set_ks_10`.
|
|
9
|
+
*/
|
|
10
|
+
function referenceCount(source, name) {
|
|
11
|
+
let count = 0;
|
|
12
|
+
for (let at = source.indexOf(name); at !== -1; at = source.indexOf(name, at + name.length)) {
|
|
13
|
+
const next = source.charCodeAt(at + name.length);
|
|
14
|
+
if (!(next >= 48 && next <= 57)) count += 1;
|
|
15
|
+
}
|
|
16
|
+
return count;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Plan exact constant initializers used by at least two validators in this file.
|
|
20
|
+
*
|
|
21
|
+
* Names are assigned per kind (`__zcSet_0`, …) and ordered by initializer text,
|
|
22
|
+
* so a given file always produces the same names for the same content.
|
|
23
|
+
*/
|
|
24
|
+
function planSharedConstants(results, constantsByResult) {
|
|
25
|
+
const byInitializer = /* @__PURE__ */ new Map();
|
|
26
|
+
for (const { codegenResult } of results) {
|
|
27
|
+
const source = `${codegenResult.code}\n${codegenResult.functionDef}`;
|
|
28
|
+
for (const constant of constantsByResult.get(codegenResult) ?? []) {
|
|
29
|
+
const declaration = `var ${constant.name}=${constant.initializer};`;
|
|
30
|
+
if (!source.includes(declaration)) continue;
|
|
31
|
+
if (referenceCount(source, constant.name) < 2) continue;
|
|
32
|
+
const entry = byInitializer.get(constant.initializer);
|
|
33
|
+
if (entry === void 0) byInitializer.set(constant.initializer, {
|
|
34
|
+
kind: constant.kind,
|
|
35
|
+
users: /* @__PURE__ */ new Set([codegenResult])
|
|
36
|
+
});
|
|
37
|
+
else entry.users.add(codegenResult);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const repeated = [...byInitializer.entries()].filter(([, entry]) => entry.users.size >= 2).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
41
|
+
const nextIndex = /* @__PURE__ */ new Map();
|
|
42
|
+
return new Map(repeated.map(([initializer, entry]) => {
|
|
43
|
+
const index = nextIndex.get(entry.kind) ?? 0;
|
|
44
|
+
nextIndex.set(entry.kind, index + 1);
|
|
45
|
+
return [initializer, `__zc${entry.kind}_${index}`];
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
function emitSharedConstants(sharedConstantNames) {
|
|
49
|
+
return [...sharedConstantNames].map(([initializer, name]) => {
|
|
50
|
+
return `var ${name}=${initializer.startsWith("new ") ? "/* @__PURE__ */" : ""}${initializer};`;
|
|
51
|
+
}).join("\n");
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
6
54
|
* Run the extract → generate pipeline for each discovered schema.
|
|
7
55
|
* Shared by CLI generate and unplugin transform.
|
|
8
56
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* to single-pass codegen (the plan is empty), paying only one linear analysis.
|
|
57
|
+
* Pass 1 extracts every schema's IR and plans repeated slow walks. Pass 2
|
|
58
|
+
* generates each validator, calling shared `__zcSw_N` functions instead of
|
|
59
|
+
* re-inlining them. Exact constant initializers reported during generation are
|
|
60
|
+
* then pooled when at least two validators use them. Files with no repetition
|
|
61
|
+
* keep their original local declarations.
|
|
15
62
|
*/
|
|
16
63
|
function compileSchemas(schemas, options) {
|
|
17
64
|
const handle = (exportName, err) => {
|
|
@@ -32,30 +79,53 @@ function compileSchemas(schemas, options) {
|
|
|
32
79
|
handle(s.exportName, err);
|
|
33
80
|
}
|
|
34
81
|
const plan = options.compact ? void 0 : createSharedSchemaPlan(extracted.map((e) => e.ir), options.mode);
|
|
35
|
-
const
|
|
82
|
+
const generated = [];
|
|
83
|
+
const constantsByResult = /* @__PURE__ */ new Map();
|
|
36
84
|
for (const e of extracted) try {
|
|
85
|
+
const constants = /* @__PURE__ */ new Map();
|
|
37
86
|
const codegenResult = generateValidator(e.ir, e.exportName, {
|
|
38
87
|
refCount: e.refEntries.length,
|
|
39
88
|
mode: options.mode,
|
|
40
89
|
sharedSchemas: plan,
|
|
41
|
-
compact: options.compact
|
|
90
|
+
compact: options.compact,
|
|
91
|
+
onConstant(constant) {
|
|
92
|
+
constants.set(constant.name, constant);
|
|
93
|
+
}
|
|
42
94
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
accessPath: ""
|
|
46
|
-
});
|
|
47
|
-
results.push({
|
|
95
|
+
constantsByResult.set(codegenResult, [...constants.values()]);
|
|
96
|
+
generated.push({
|
|
48
97
|
exportName: e.exportName,
|
|
49
|
-
|
|
50
|
-
|
|
98
|
+
schema: e.schema,
|
|
99
|
+
ir: e.ir,
|
|
100
|
+
refEntries: e.refEntries,
|
|
101
|
+
codegenResult
|
|
51
102
|
});
|
|
52
103
|
} catch (err) {
|
|
53
104
|
handle(e.exportName, err);
|
|
54
105
|
}
|
|
106
|
+
const sharedConstantNames = planSharedConstants(generated.map(({ exportName, codegenResult, refEntries }) => ({
|
|
107
|
+
exportName,
|
|
108
|
+
codegenResult,
|
|
109
|
+
refEntries
|
|
110
|
+
})), constantsByResult);
|
|
111
|
+
if (sharedConstantNames.size > 0) for (const entry of generated) entry.codegenResult = generateValidator(entry.ir, entry.exportName, {
|
|
112
|
+
refCount: entry.refEntries.length,
|
|
113
|
+
mode: options.mode,
|
|
114
|
+
sharedSchemas: plan,
|
|
115
|
+
compact: options.compact,
|
|
116
|
+
sharedConstantNames
|
|
117
|
+
});
|
|
118
|
+
const results = generated.map((entry) => ({
|
|
119
|
+
exportName: entry.exportName,
|
|
120
|
+
codegenResult: entry.codegenResult,
|
|
121
|
+
refEntries: entry.refEntries
|
|
122
|
+
}));
|
|
123
|
+
const sharedConstantCode = emitSharedConstants(sharedConstantNames);
|
|
124
|
+
const slowWalkCode = plan?.code ?? "";
|
|
55
125
|
return {
|
|
56
126
|
schemas: results,
|
|
57
127
|
shared: {
|
|
58
|
-
code:
|
|
128
|
+
code: sharedConstantCode === "" ? slowWalkCode : slowWalkCode === "" ? `${SHARED_BLOCK_MARKER}\n${sharedConstantCode}` : `${slowWalkCode}\n${sharedConstantCode}`,
|
|
59
129
|
usedHelpers: plan?.usedHelpers ?? /* @__PURE__ */ new Set()
|
|
60
130
|
}
|
|
61
131
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.js","names":[],"sources":["../../src/core/pipeline.ts"],"sourcesContent":["import type { CodeGenResult, CodegenMode } from \"./codegen/context.js\";\nimport { createSharedSchemaPlan } from \"./codegen/dedupe.js\";\nimport { generateValidator } from \"./codegen/index.js\";\nimport type { RefEntry } from \"./extract/index.js\";\nimport { extractSchema } from \"./extract/index.js\";\nimport type { DiscoveredSchema, SchemaIR } from \"./types.js\";\n\n/** Result of compiling a single discovered schema through extract → generate pipeline. */\nexport interface CompiledSchemaInfo {\n exportName: string;\n codegenResult: CodeGenResult;\n refEntries: RefEntry[];\n}\n\n/** Module-scope shared-validator declarations produced by file-level dedup. */\nexport interface SharedSchemaBlock {\n /** Shared `__zcSw_N` functions + their preamble. Empty string when nothing repeated. */\n code: string;\n /** Runtime helper names referenced by the shared block (lean mode imports). */\n usedHelpers: Set<string>;\n}\n\n/** Output of {@link compileSchemas}: per-schema validators plus the file's shared block. */\nexport interface CompileSchemasResult {\n schemas: CompiledSchemaInfo[];\n shared: SharedSchemaBlock;\n}\n\nexport interface CompileSchemasOptions {\n /** \"inline\" for CLI .compiled.ts; \"lean\" for unplugin (imports from virtual:zod-compiler/runtime). */\n mode: CodegenMode;\n /**\n * Compact output (`output: \"compact\"`). Drop the compiled slow walk for\n * mutation-free, total-fast-path schemas and delegate their cold error path\n * to the retained Zod schema. Disables slow-walk sharing (delegated schemas\n * never emit a walk to share) and appends a root self-RefEntry per delegated\n * schema so `__rf[N]` resolves to the original Zod schema.\n */\n compact?: boolean | undefined;\n /** When provided, per-schema failures call this and continue. Otherwise the first error throws. */\n onError?: (exportName: string, error: Error) => void;\n}\n\n/**\n * Run the extract → generate pipeline for each discovered schema.\n * Shared by CLI generate and unplugin transform.\n *\n * Two passes so structurally repeated schemas can be deduplicated: pass 1\n * extracts every schema's IR, then a file-level plan hoists the slow walk of\n * any shape that recurs across schemas into a shared `__zcSw_N` function; pass\n * 2 generates each validator, calling the shared walk instead of re-inlining\n * it. Files with no repetition take the same path and produce identical output\n * to single-pass codegen (the plan is empty), paying only one linear analysis.\n */\nexport function compileSchemas(\n schemas: DiscoveredSchema[],\n options: CompileSchemasOptions,\n): CompileSchemasResult {\n const handle = (exportName: string, err: unknown): void => {\n if (options.onError) {\n options.onError(exportName, err instanceof Error ? err : new Error(String(err)));\n } else {\n throw err;\n }\n };\n\n // Pass 1: extract IR (and fallback refs) for every schema.\n const extracted: Array<{\n exportName: string;\n schema: unknown;\n ir: SchemaIR;\n refEntries: RefEntry[];\n }> = [];\n for (const s of schemas) {\n try {\n const refEntries: RefEntry[] = [];\n const ir = extractSchema(s.schema, refEntries);\n extracted.push({ exportName: s.exportName, schema: s.schema, ir, refEntries });\n } catch (err) {\n handle(s.exportName, err);\n }\n }\n\n // Compact mode delegates the cold error path of total-fast-path schemas to\n // zod, so they emit no slow walk to share — skip the plan (and the dead\n // shared functions it would generate for shapes that now only delegate).\n const plan = options.compact\n ? undefined\n : createSharedSchemaPlan(\n extracted.map((e) => e.ir),\n options.mode,\n );\n\n // Pass 2: generate each validator, sharing repeated slow walks via the plan.\n const results: CompiledSchemaInfo[] = [];\n for (const e of extracted) {\n try {\n const codegenResult = generateValidator(e.ir, e.exportName, {\n refCount: e.refEntries.length,\n mode: options.mode,\n sharedSchemas: plan,\n compact: options.compact,\n });\n // Compact delegation appends the schema itself as a fresh root RefEntry\n // (accessPath \"\" → __rf[N] = the original Zod schema, whose pristine\n // safeParse the validator delegates to). The index was reserved as\n // e.refEntries.length above, so this push lands exactly at it.\n if (codegenResult.rootDelegateRefIndex !== undefined) {\n e.refEntries.push({ schema: e.schema, accessPath: \"\" });\n }\n results.push({ exportName: e.exportName, codegenResult, refEntries: e.refEntries });\n } catch (err) {\n handle(e.exportName, err);\n }\n }\n\n return {\n schemas: results,\n shared: { code: plan?.code ?? \"\", usedHelpers: plan?.usedHelpers ?? new Set() },\n };\n}\n\n/**\n * Aggregate `usedHelpers` across multiple compiled schemas (typically all schemas in one file).\n * Used by the unplugin transform to construct a single import statement per file.\n */\nexport function aggregateUsedHelpers(schemas: CompiledSchemaInfo[]): Set<string> {\n const all = new Set<string>();\n for (const s of schemas) {\n for (const h of s.codegenResult.usedHelpers) all.add(h);\n }\n return all;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAsDA,SAAgB,eACd,SACA,SACsB;CACtB,MAAM,UAAU,YAAoB,QAAuB;EACzD,IAAI,QAAQ,SACV,QAAQ,QAAQ,YAAY,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;OAE/E,MAAM;CAEV;CAGA,MAAM,YAKD,CAAC;CACN,KAAK,MAAM,KAAK,SACd,IAAI;EACF,MAAM,aAAyB,CAAC;EAChC,MAAM,KAAK,cAAc,EAAE,QAAQ,UAAU;EAC7C,UAAU,KAAK;GAAE,YAAY,EAAE;GAAY,QAAQ,EAAE;GAAQ;GAAI;EAAW,CAAC;CAC/E,SAAS,KAAK;EACZ,OAAO,EAAE,YAAY,GAAG;CAC1B;CAMF,MAAM,OAAO,QAAQ,UACjB,KAAA,IACA,uBACE,UAAU,KAAK,MAAM,EAAE,EAAE,GACzB,QAAQ,IACV;CAGJ,MAAM,UAAgC,CAAC;CACvC,KAAK,MAAM,KAAK,WACd,IAAI;EACF,MAAM,gBAAgB,kBAAkB,EAAE,IAAI,EAAE,YAAY;GAC1D,UAAU,EAAE,WAAW;GACvB,MAAM,QAAQ;GACd,eAAe;GACf,SAAS,QAAQ;EACnB,CAAC;EAKD,IAAI,cAAc,yBAAyB,KAAA,GACzC,EAAE,WAAW,KAAK;GAAE,QAAQ,EAAE;GAAQ,YAAY;EAAG,CAAC;EAExD,QAAQ,KAAK;GAAE,YAAY,EAAE;GAAY;GAAe,YAAY,EAAE;EAAW,CAAC;CACpF,SAAS,KAAK;EACZ,OAAO,EAAE,YAAY,GAAG;CAC1B;CAGF,OAAO;EACL,SAAS;EACT,QAAQ;GAAE,MAAM,MAAM,QAAQ;GAAI,aAAa,MAAM,+BAAe,IAAI,IAAI;EAAE;CAChF;AACF;;;;;AAMA,SAAgB,qBAAqB,SAA4C;CAC/E,MAAM,sBAAM,IAAI,IAAY;CAC5B,KAAK,MAAM,KAAK,SACd,KAAK,MAAM,KAAK,EAAE,cAAc,aAAa,IAAI,IAAI,CAAC;CAExD,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"pipeline.js","names":[],"sources":["../../src/core/pipeline.ts"],"sourcesContent":["import type {\n CodeGenResult,\n CodegenMode,\n ConstantKind,\n GeneratedConstant,\n} from \"./codegen/context.js\";\nimport { createSharedSchemaPlan, SHARED_BLOCK_MARKER } from \"./codegen/dedupe.js\";\nimport { generateValidator } from \"./codegen/index.js\";\nimport type { RefEntry } from \"./extract/index.js\";\nimport { extractSchema } from \"./extract/index.js\";\nimport type { DiscoveredSchema, SchemaIR } from \"./types.js\";\n\n/** Result of compiling a single discovered schema through extract → generate pipeline. */\nexport interface CompiledSchemaInfo {\n exportName: string;\n codegenResult: CodeGenResult;\n refEntries: RefEntry[];\n}\n\n/** Module-scope declarations produced by file-level schema and constant dedup. */\nexport interface SharedSchemaBlock {\n /** Shared constants and `__zcSw_N` functions. Empty string when nothing repeats. */\n code: string;\n /** Runtime helper names referenced by the shared block (lean mode imports). */\n usedHelpers: Set<string>;\n}\n\n/** Output of {@link compileSchemas}: per-schema validators plus the file's shared block. */\nexport interface CompileSchemasResult {\n schemas: CompiledSchemaInfo[];\n shared: SharedSchemaBlock;\n}\n\nexport interface CompileSchemasOptions {\n /** \"inline\" for CLI .compiled.ts; \"lean\" for unplugin (imports from virtual:zod-compiler/runtime). */\n mode: CodegenMode;\n /**\n * Compact output (`output: \"compact\"`). Drop the compiled slow walk for\n * mutation-free, total-fast-path schemas and delegate their cold error path\n * to the retained Zod schema. Disables slow-walk sharing (delegated schemas\n * never emit a walk to share); delegated validators read the retained schema\n * through the `__zs` binding rather than through `__rf[]`.\n */\n compact?: boolean | undefined;\n /** When provided, per-schema failures call this and continue. Otherwise the first error throws. */\n onError?: (exportName: string, error: Error) => void;\n}\n\n/**\n * Occurrences of a generated identifier in `source`, ignoring the longer names\n * it is a prefix of — every generated name ends in `_<digits>`, so `__set_ks_1`\n * would otherwise count itself inside `__set_ks_10`.\n */\nfunction referenceCount(source: string, name: string): number {\n let count = 0;\n for (let at = source.indexOf(name); at !== -1; at = source.indexOf(name, at + name.length)) {\n const next = source.charCodeAt(at + name.length);\n if (!(next >= 48 && next <= 57)) count += 1;\n }\n return count;\n}\n\n/**\n * Plan exact constant initializers used by at least two validators in this file.\n *\n * Names are assigned per kind (`__zcSet_0`, …) and ordered by initializer text,\n * so a given file always produces the same names for the same content.\n */\nfunction planSharedConstants(\n results: readonly CompiledSchemaInfo[],\n constantsByResult: ReadonlyMap<CodeGenResult, readonly GeneratedConstant[]>,\n): ReadonlyMap<string, string> {\n const byInitializer = new Map<string, { kind: ConstantKind; users: Set<CodeGenResult> }>();\n for (const { codegenResult } of results) {\n const source = `${codegenResult.code}\\n${codegenResult.functionDef}`;\n for (const constant of constantsByResult.get(codegenResult) ?? []) {\n const declaration = `var ${constant.name}=${constant.initializer};`;\n // Fast-path generation can emit a constant before a later node aborts.\n // Its preamble is rolled back, so only collect declarations that survived.\n if (!source.includes(declaration)) continue;\n // A surviving declaration is not the same as a use. Two generators emit a\n // constant before they can decline — the build path names its FAIL\n // sentinel up front, and an abandoned fast-path walk leaves whatever it\n // declared behind — so a validator can hold a declaration it never reads.\n // Counting those as pool users hoisted constants nothing referenced, and\n // (worse) tripped the regeneration pass for a file that gained nothing by\n // it. Require the name to appear at least once beyond its own declaration.\n if (referenceCount(source, constant.name) < 2) continue;\n const entry = byInitializer.get(constant.initializer);\n if (entry === undefined) {\n byInitializer.set(constant.initializer, {\n kind: constant.kind,\n users: new Set([codegenResult]),\n });\n } else {\n entry.users.add(codegenResult);\n }\n }\n }\n\n const repeated = [...byInitializer.entries()]\n .filter(([, entry]) => entry.users.size >= 2)\n .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));\n\n const nextIndex = new Map<ConstantKind, number>();\n return new Map(\n repeated.map(([initializer, entry]) => {\n const index = nextIndex.get(entry.kind) ?? 0;\n nextIndex.set(entry.kind, index + 1);\n return [initializer, `__zc${entry.kind}_${index}`];\n }),\n );\n}\n\nfunction emitSharedConstants(sharedConstantNames: ReadonlyMap<string, string>): string {\n return [...sharedConstantNames]\n .map(([initializer, name]) => {\n // `/* @__PURE__ */` earns its bytes only on a constructor call, where it\n // tells a bundler the declaration is droppable when nothing reads it. On a\n // plain object literal it is inert, and the annotation is longer than the\n // initializer it annotates.\n const pure = initializer.startsWith(\"new \") ? \"/* @__PURE__ */\" : \"\";\n return `var ${name}=${pure}${initializer};`;\n })\n .join(\"\\n\");\n}\n\n/**\n * Run the extract → generate pipeline for each discovered schema.\n * Shared by CLI generate and unplugin transform.\n *\n * Pass 1 extracts every schema's IR and plans repeated slow walks. Pass 2\n * generates each validator, calling shared `__zcSw_N` functions instead of\n * re-inlining them. Exact constant initializers reported during generation are\n * then pooled when at least two validators use them. Files with no repetition\n * keep their original local declarations.\n */\nexport function compileSchemas(\n schemas: DiscoveredSchema[],\n options: CompileSchemasOptions,\n): CompileSchemasResult {\n const handle = (exportName: string, err: unknown): void => {\n if (options.onError) {\n options.onError(exportName, err instanceof Error ? err : new Error(String(err)));\n } else {\n throw err;\n }\n };\n\n // Pass 1: extract IR (and fallback refs) for every schema.\n const extracted: Array<{\n exportName: string;\n schema: unknown;\n ir: SchemaIR;\n refEntries: RefEntry[];\n }> = [];\n for (const s of schemas) {\n try {\n const refEntries: RefEntry[] = [];\n const ir = extractSchema(s.schema, refEntries);\n extracted.push({ exportName: s.exportName, schema: s.schema, ir, refEntries });\n } catch (err) {\n handle(s.exportName, err);\n }\n }\n\n // Compact mode delegates the cold error path of total-fast-path schemas to\n // zod, so they emit no slow walk to share — skip the plan (and the dead\n // shared functions it would generate for shapes that now only delegate).\n const plan = options.compact\n ? undefined\n : createSharedSchemaPlan(\n extracted.map((e) => e.ir),\n options.mode,\n );\n\n // Pass 2: generate each validator, sharing repeated slow walks via the plan\n // and observing which constant declarations survive codegen rollback.\n const generated: Array<{\n exportName: string;\n schema: unknown;\n ir: SchemaIR;\n refEntries: RefEntry[];\n codegenResult: CodeGenResult;\n }> = [];\n const constantsByResult = new Map<CodeGenResult, GeneratedConstant[]>();\n for (const e of extracted) {\n try {\n const constants = new Map<string, GeneratedConstant>();\n const codegenResult = generateValidator(e.ir, e.exportName, {\n refCount: e.refEntries.length,\n mode: options.mode,\n sharedSchemas: plan,\n compact: options.compact,\n onConstant(constant) {\n constants.set(constant.name, constant);\n },\n });\n constantsByResult.set(codegenResult, [...constants.values()]);\n generated.push({\n exportName: e.exportName,\n schema: e.schema,\n ir: e.ir,\n refEntries: e.refEntries,\n codegenResult,\n });\n } catch (err) {\n handle(e.exportName, err);\n }\n }\n\n const initialResults = generated.map(\n ({ exportName, codegenResult, refEntries }): CompiledSchemaInfo => ({\n exportName,\n codegenResult,\n refEntries,\n }),\n );\n const sharedConstantNames = planSharedConstants(initialResults, constantsByResult);\n\n // Regenerate only when sharing is profitable. Selecting shared names before\n // emission avoids textual rewriting of generated JavaScript, where a user\n // enum string can legally contain text resembling a generated identifier.\n if (sharedConstantNames.size > 0) {\n for (const entry of generated) {\n entry.codegenResult = generateValidator(entry.ir, entry.exportName, {\n refCount: entry.refEntries.length,\n mode: options.mode,\n sharedSchemas: plan,\n compact: options.compact,\n sharedConstantNames,\n });\n }\n }\n\n const results: CompiledSchemaInfo[] = generated.map((entry) => ({\n exportName: entry.exportName,\n codegenResult: entry.codegenResult,\n refEntries: entry.refEntries,\n }));\n\n const sharedConstantCode = emitSharedConstants(sharedConstantNames);\n const slowWalkCode = plan?.code ?? \"\";\n const sharedCode =\n sharedConstantCode === \"\"\n ? slowWalkCode\n : slowWalkCode === \"\"\n ? `${SHARED_BLOCK_MARKER}\\n${sharedConstantCode}`\n : `${slowWalkCode}\\n${sharedConstantCode}`;\n\n return {\n schemas: results,\n shared: { code: sharedCode, usedHelpers: plan?.usedHelpers ?? new Set() },\n };\n}\n\n/**\n * Aggregate `usedHelpers` across multiple compiled schemas (typically all schemas in one file).\n * Used by the unplugin transform to construct a single import statement per file.\n */\nexport function aggregateUsedHelpers(schemas: CompiledSchemaInfo[]): Set<string> {\n const all = new Set<string>();\n for (const s of schemas) {\n for (const h of s.codegenResult.usedHelpers) all.add(h);\n }\n return all;\n}\n"],"mappings":";;;;;;;;;AAqDA,SAAS,eAAe,QAAgB,MAAsB;CAC5D,IAAI,QAAQ;CACZ,KAAK,IAAI,KAAK,OAAO,QAAQ,IAAI,GAAG,OAAO,IAAI,KAAK,OAAO,QAAQ,MAAM,KAAK,KAAK,MAAM,GAAG;EAC1F,MAAM,OAAO,OAAO,WAAW,KAAK,KAAK,MAAM;EAC/C,IAAI,EAAE,QAAQ,MAAM,QAAQ,KAAK,SAAS;CAC5C;CACA,OAAO;AACT;;;;;;;AAQA,SAAS,oBACP,SACA,mBAC6B;CAC7B,MAAM,gCAAgB,IAAI,IAA+D;CACzF,KAAK,MAAM,EAAE,mBAAmB,SAAS;EACvC,MAAM,SAAS,GAAG,cAAc,KAAK,IAAI,cAAc;EACvD,KAAK,MAAM,YAAY,kBAAkB,IAAI,aAAa,KAAK,CAAC,GAAG;GACjE,MAAM,cAAc,OAAO,SAAS,KAAK,GAAG,SAAS,YAAY;GAGjE,IAAI,CAAC,OAAO,SAAS,WAAW,GAAG;GAQnC,IAAI,eAAe,QAAQ,SAAS,IAAI,IAAI,GAAG;GAC/C,MAAM,QAAQ,cAAc,IAAI,SAAS,WAAW;GACpD,IAAI,UAAU,KAAA,GACZ,cAAc,IAAI,SAAS,aAAa;IACtC,MAAM,SAAS;IACf,uBAAO,IAAI,IAAI,CAAC,aAAa,CAAC;GAChC,CAAC;QAED,MAAM,MAAM,IAAI,aAAa;EAEjC;CACF;CAEA,MAAM,WAAW,CAAC,GAAG,cAAc,QAAQ,CAAC,CAAC,CAC1C,QAAQ,GAAG,WAAW,MAAM,MAAM,QAAQ,CAAC,CAAC,CAC5C,MAAM,CAAC,IAAI,CAAC,OAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAE;CAElD,MAAM,4BAAY,IAAI,IAA0B;CAChD,OAAO,IAAI,IACT,SAAS,KAAK,CAAC,aAAa,WAAW;EACrC,MAAM,QAAQ,UAAU,IAAI,MAAM,IAAI,KAAK;EAC3C,UAAU,IAAI,MAAM,MAAM,QAAQ,CAAC;EACnC,OAAO,CAAC,aAAa,OAAO,MAAM,KAAK,GAAG,OAAO;CACnD,CAAC,CACH;AACF;AAEA,SAAS,oBAAoB,qBAA0D;CACrF,OAAO,CAAC,GAAG,mBAAmB,CAAC,CAC5B,KAAK,CAAC,aAAa,UAAU;EAM5B,OAAO,OAAO,KAAK,GADN,YAAY,WAAW,MAAM,IAAI,oBAAoB,KACrC,YAAY;CAC3C,CAAC,CAAC,CACD,KAAK,IAAI;AACd;;;;;;;;;;;AAYA,SAAgB,eACd,SACA,SACsB;CACtB,MAAM,UAAU,YAAoB,QAAuB;EACzD,IAAI,QAAQ,SACV,QAAQ,QAAQ,YAAY,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;OAE/E,MAAM;CAEV;CAGA,MAAM,YAKD,CAAC;CACN,KAAK,MAAM,KAAK,SACd,IAAI;EACF,MAAM,aAAyB,CAAC;EAChC,MAAM,KAAK,cAAc,EAAE,QAAQ,UAAU;EAC7C,UAAU,KAAK;GAAE,YAAY,EAAE;GAAY,QAAQ,EAAE;GAAQ;GAAI;EAAW,CAAC;CAC/E,SAAS,KAAK;EACZ,OAAO,EAAE,YAAY,GAAG;CAC1B;CAMF,MAAM,OAAO,QAAQ,UACjB,KAAA,IACA,uBACE,UAAU,KAAK,MAAM,EAAE,EAAE,GACzB,QAAQ,IACV;CAIJ,MAAM,YAMD,CAAC;CACN,MAAM,oCAAoB,IAAI,IAAwC;CACtE,KAAK,MAAM,KAAK,WACd,IAAI;EACF,MAAM,4BAAY,IAAI,IAA+B;EACrD,MAAM,gBAAgB,kBAAkB,EAAE,IAAI,EAAE,YAAY;GAC1D,UAAU,EAAE,WAAW;GACvB,MAAM,QAAQ;GACd,eAAe;GACf,SAAS,QAAQ;GACjB,WAAW,UAAU;IACnB,UAAU,IAAI,SAAS,MAAM,QAAQ;GACvC;EACF,CAAC;EACD,kBAAkB,IAAI,eAAe,CAAC,GAAG,UAAU,OAAO,CAAC,CAAC;EAC5D,UAAU,KAAK;GACb,YAAY,EAAE;GACd,QAAQ,EAAE;GACV,IAAI,EAAE;GACN,YAAY,EAAE;GACd;EACF,CAAC;CACH,SAAS,KAAK;EACZ,OAAO,EAAE,YAAY,GAAG;CAC1B;CAUF,MAAM,sBAAsB,oBAPL,UAAU,KAC9B,EAAE,YAAY,eAAe,kBAAsC;EAClE;EACA;EACA;CACF,EAE2D,GAAG,iBAAiB;CAKjF,IAAI,oBAAoB,OAAO,GAC7B,KAAK,MAAM,SAAS,WAClB,MAAM,gBAAgB,kBAAkB,MAAM,IAAI,MAAM,YAAY;EAClE,UAAU,MAAM,WAAW;EAC3B,MAAM,QAAQ;EACd,eAAe;EACf,SAAS,QAAQ;EACjB;CACF,CAAC;CAIL,MAAM,UAAgC,UAAU,KAAK,WAAW;EAC9D,YAAY,MAAM;EAClB,eAAe,MAAM;EACrB,YAAY,MAAM;CACpB,EAAE;CAEF,MAAM,qBAAqB,oBAAoB,mBAAmB;CAClE,MAAM,eAAe,MAAM,QAAQ;CAQnC,OAAO;EACL,SAAS;EACT,QAAQ;GAAE,MARV,uBAAuB,KACnB,eACA,iBAAiB,KACf,GAAG,oBAAoB,IAAI,uBAC3B,GAAG,aAAa,IAAI;GAIE,aAAa,MAAM,+BAAe,IAAI,IAAI;EAAE;CAC1E;AACF;;;;;AAMA,SAAgB,qBAAqB,SAA4C;CAC/E,MAAM,sBAAM,IAAI,IAAY;CAC5B,KAAK,MAAM,KAAK,SACd,KAAK,MAAM,KAAK,EAAE,cAAc,aAAa,IAAI,IAAI,CAAC;CAExD,OAAO;AACT"}
|
package/dist/jit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jit.d.ts","names":[],"sources":["../src/jit.ts"],"mappings":";;;UA4EiB;;;;;;;EAOf;;;;;;;;;;;;;;;;;;;;;;;iBAwBc,IAAI,UAAU,SAC5B,QAAQ,GACR,UAAU,aACT,IAAI,eAAe,OAAO;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"jit.d.ts","names":[],"sources":["../src/jit.ts"],"mappings":";;;UA4EiB;;;;;;;EAOf;;;;;;;;;;;;;;;;;;;;;;;iBAwBc,IAAI,UAAU,SAC5B,QAAQ,GACR,UAAU,aACT,IAAI,eAAe,OAAO;;;;;;;;;;;;;;iBAkHb,OAAO,iBAAiB,UAAU"}
|