zod-compiler 1.23.0 → 1.23.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.
Files changed (494) hide show
  1. package/README.md +9 -6
  2. package/dist/cli/commands/check.d.ts +10 -7
  3. package/dist/cli/commands/check.d.ts.map +1 -1
  4. package/dist/cli/commands/check.js +125 -148
  5. package/dist/cli/commands/check.js.map +1 -1
  6. package/dist/cli/commands/generate.d.ts +22 -19
  7. package/dist/cli/commands/generate.d.ts.map +1 -1
  8. package/dist/cli/commands/generate.js +102 -133
  9. package/dist/cli/commands/generate.js.map +1 -1
  10. package/dist/cli/commands/watch.d.ts +17 -15
  11. package/dist/cli/commands/watch.d.ts.map +1 -1
  12. package/dist/cli/commands/watch.js +126 -154
  13. package/dist/cli/commands/watch.js.map +1 -1
  14. package/dist/cli/emitter.d.ts +19 -16
  15. package/dist/cli/emitter.d.ts.map +1 -1
  16. package/dist/cli/emitter.js +55 -71
  17. package/dist/cli/emitter.js.map +1 -1
  18. package/dist/cli/errors.d.ts +4 -1
  19. package/dist/cli/errors.d.ts.map +1 -1
  20. package/dist/cli/errors.js +6 -2
  21. package/dist/cli/errors.js.map +1 -1
  22. package/dist/cli/index.d.ts +1 -3
  23. package/dist/cli/index.js +147 -160
  24. package/dist/cli/index.js.map +1 -1
  25. package/dist/cli/logger.d.ts +18 -15
  26. package/dist/cli/logger.d.ts.map +1 -1
  27. package/dist/cli/logger.js +38 -37
  28. package/dist/cli/logger.js.map +1 -1
  29. package/dist/core/codegen/build-path.d.ts +7 -41
  30. package/dist/core/codegen/build-path.d.ts.map +1 -1
  31. package/dist/core/codegen/build-path.js +481 -570
  32. package/dist/core/codegen/build-path.js.map +1 -1
  33. package/dist/core/codegen/context.d.ts +256 -253
  34. package/dist/core/codegen/context.d.ts.map +1 -1
  35. package/dist/core/codegen/context.js +363 -437
  36. package/dist/core/codegen/context.js.map +1 -1
  37. package/dist/core/codegen/dedupe.d.ts +22 -56
  38. package/dist/core/codegen/dedupe.d.ts.map +1 -1
  39. package/dist/core/codegen/dedupe.js +150 -242
  40. package/dist/core/codegen/dedupe.js.map +1 -1
  41. package/dist/core/codegen/emit-issue.d.ts +44 -68
  42. package/dist/core/codegen/emit-issue.d.ts.map +1 -1
  43. package/dist/core/codegen/emit-issue.js +76 -108
  44. package/dist/core/codegen/emit-issue.js.map +1 -1
  45. package/dist/core/codegen/emit.d.ts +4 -1
  46. package/dist/core/codegen/emit.d.ts.map +1 -1
  47. package/dist/core/codegen/emit.js +16 -13
  48. package/dist/core/codegen/emit.js.map +1 -1
  49. package/dist/core/codegen/fast-path.d.ts +7 -12
  50. package/dist/core/codegen/fast-path.d.ts.map +1 -1
  51. package/dist/core/codegen/fast-path.js +116 -145
  52. package/dist/core/codegen/fast-path.js.map +1 -1
  53. package/dist/core/codegen/fast-size.d.ts +12 -26
  54. package/dist/core/codegen/fast-size.d.ts.map +1 -1
  55. package/dist/core/codegen/fast-size.js +169 -244
  56. package/dist/core/codegen/fast-size.js.map +1 -1
  57. package/dist/core/codegen/index.d.ts +25 -23
  58. package/dist/core/codegen/index.d.ts.map +1 -1
  59. package/dist/core/codegen/index.js +239 -405
  60. package/dist/core/codegen/index.js.map +1 -1
  61. package/dist/core/codegen/issue-decls.d.ts +15 -12
  62. package/dist/core/codegen/issue-decls.d.ts.map +1 -1
  63. package/dist/core/codegen/issue-decls.js +131 -162
  64. package/dist/core/codegen/issue-decls.js.map +1 -1
  65. package/dist/core/codegen/regex-unroll.d.ts +4 -1
  66. package/dist/core/codegen/regex-unroll.d.ts.map +1 -1
  67. package/dist/core/codegen/regex-unroll.js +173 -197
  68. package/dist/core/codegen/regex-unroll.js.map +1 -1
  69. package/dist/core/codegen/schemas/any.d.ts +7 -4
  70. package/dist/core/codegen/schemas/any.d.ts.map +1 -1
  71. package/dist/core/codegen/schemas/any.js +8 -4
  72. package/dist/core/codegen/schemas/any.js.map +1 -1
  73. package/dist/core/codegen/schemas/array.d.ts +8 -5
  74. package/dist/core/codegen/schemas/array.d.ts.map +1 -1
  75. package/dist/core/codegen/schemas/array.js +77 -95
  76. package/dist/core/codegen/schemas/array.js.map +1 -1
  77. package/dist/core/codegen/schemas/bigint.d.ts +7 -4
  78. package/dist/core/codegen/schemas/bigint.d.ts.map +1 -1
  79. package/dist/core/codegen/schemas/bigint.js +44 -56
  80. package/dist/core/codegen/schemas/bigint.js.map +1 -1
  81. package/dist/core/codegen/schemas/boolean.d.ts +7 -4
  82. package/dist/core/codegen/schemas/boolean.d.ts.map +1 -1
  83. package/dist/core/codegen/schemas/boolean.js +12 -11
  84. package/dist/core/codegen/schemas/boolean.js.map +1 -1
  85. package/dist/core/codegen/schemas/catch.d.ts +8 -5
  86. package/dist/core/codegen/schemas/catch.d.ts.map +1 -1
  87. package/dist/core/codegen/schemas/catch.js +23 -23
  88. package/dist/core/codegen/schemas/catch.js.map +1 -1
  89. package/dist/core/codegen/schemas/date.d.ts +7 -4
  90. package/dist/core/codegen/schemas/date.d.ts.map +1 -1
  91. package/dist/core/codegen/schemas/date.js +49 -68
  92. package/dist/core/codegen/schemas/date.js.map +1 -1
  93. package/dist/core/codegen/schemas/default.d.ts +9 -6
  94. package/dist/core/codegen/schemas/default.d.ts.map +1 -1
  95. package/dist/core/codegen/schemas/default.js +29 -27
  96. package/dist/core/codegen/schemas/default.js.map +1 -1
  97. package/dist/core/codegen/schemas/discriminated-union.d.ts +12 -10
  98. package/dist/core/codegen/schemas/discriminated-union.d.ts.map +1 -1
  99. package/dist/core/codegen/schemas/discriminated-union.js +153 -178
  100. package/dist/core/codegen/schemas/discriminated-union.js.map +1 -1
  101. package/dist/core/codegen/schemas/effect.d.ts +9 -6
  102. package/dist/core/codegen/schemas/effect.d.ts.map +1 -1
  103. package/dist/core/codegen/schemas/effect.js +54 -67
  104. package/dist/core/codegen/schemas/effect.js.map +1 -1
  105. package/dist/core/codegen/schemas/enum.d.ts +7 -4
  106. package/dist/core/codegen/schemas/enum.d.ts.map +1 -1
  107. package/dist/core/codegen/schemas/enum.js +15 -21
  108. package/dist/core/codegen/schemas/enum.js.map +1 -1
  109. package/dist/core/codegen/schemas/fallback.d.ts +6 -3
  110. package/dist/core/codegen/schemas/fallback.d.ts.map +1 -1
  111. package/dist/core/codegen/schemas/fallback.js +14 -13
  112. package/dist/core/codegen/schemas/fallback.js.map +1 -1
  113. package/dist/core/codegen/schemas/file.d.ts +7 -4
  114. package/dist/core/codegen/schemas/file.d.ts.map +1 -1
  115. package/dist/core/codegen/schemas/file.js +51 -57
  116. package/dist/core/codegen/schemas/file.js.map +1 -1
  117. package/dist/core/codegen/schemas/intersection.d.ts +8 -5
  118. package/dist/core/codegen/schemas/intersection.d.ts.map +1 -1
  119. package/dist/core/codegen/schemas/intersection.js +16 -13
  120. package/dist/core/codegen/schemas/intersection.js.map +1 -1
  121. package/dist/core/codegen/schemas/literal.d.ts +7 -4
  122. package/dist/core/codegen/schemas/literal.d.ts.map +1 -1
  123. package/dist/core/codegen/schemas/literal.js +20 -23
  124. package/dist/core/codegen/schemas/literal.js.map +1 -1
  125. package/dist/core/codegen/schemas/map.d.ts +8 -5
  126. package/dist/core/codegen/schemas/map.d.ts.map +1 -1
  127. package/dist/core/codegen/schemas/map.js +61 -67
  128. package/dist/core/codegen/schemas/map.js.map +1 -1
  129. package/dist/core/codegen/schemas/nan.d.ts +7 -4
  130. package/dist/core/codegen/schemas/nan.d.ts.map +1 -1
  131. package/dist/core/codegen/schemas/nan.js +8 -4
  132. package/dist/core/codegen/schemas/nan.js.map +1 -1
  133. package/dist/core/codegen/schemas/never.d.ts +7 -4
  134. package/dist/core/codegen/schemas/never.d.ts.map +1 -1
  135. package/dist/core/codegen/schemas/never.js +8 -4
  136. package/dist/core/codegen/schemas/never.js.map +1 -1
  137. package/dist/core/codegen/schemas/null.d.ts +7 -4
  138. package/dist/core/codegen/schemas/null.d.ts.map +1 -1
  139. package/dist/core/codegen/schemas/null.js +8 -4
  140. package/dist/core/codegen/schemas/null.js.map +1 -1
  141. package/dist/core/codegen/schemas/nullable.d.ts +8 -5
  142. package/dist/core/codegen/schemas/nullable.d.ts.map +1 -1
  143. package/dist/core/codegen/schemas/nullable.js +8 -5
  144. package/dist/core/codegen/schemas/nullable.js.map +1 -1
  145. package/dist/core/codegen/schemas/number.d.ts +7 -4
  146. package/dist/core/codegen/schemas/number.d.ts.map +1 -1
  147. package/dist/core/codegen/schemas/number.js +120 -176
  148. package/dist/core/codegen/schemas/number.js.map +1 -1
  149. package/dist/core/codegen/schemas/object.d.ts +8 -5
  150. package/dist/core/codegen/schemas/object.d.ts.map +1 -1
  151. package/dist/core/codegen/schemas/object.js +144 -231
  152. package/dist/core/codegen/schemas/object.js.map +1 -1
  153. package/dist/core/codegen/schemas/optional.d.ts +9 -6
  154. package/dist/core/codegen/schemas/optional.d.ts.map +1 -1
  155. package/dist/core/codegen/schemas/optional.js +23 -31
  156. package/dist/core/codegen/schemas/optional.js.map +1 -1
  157. package/dist/core/codegen/schemas/pipe.d.ts +8 -5
  158. package/dist/core/codegen/schemas/pipe.d.ts.map +1 -1
  159. package/dist/core/codegen/schemas/pipe.js +20 -27
  160. package/dist/core/codegen/schemas/pipe.js.map +1 -1
  161. package/dist/core/codegen/schemas/readonly.d.ts +8 -5
  162. package/dist/core/codegen/schemas/readonly.d.ts.map +1 -1
  163. package/dist/core/codegen/schemas/readonly.js +8 -5
  164. package/dist/core/codegen/schemas/readonly.js.map +1 -1
  165. package/dist/core/codegen/schemas/record.d.ts +8 -5
  166. package/dist/core/codegen/schemas/record.d.ts.map +1 -1
  167. package/dist/core/codegen/schemas/record.js +52 -65
  168. package/dist/core/codegen/schemas/record.js.map +1 -1
  169. package/dist/core/codegen/schemas/recursive-ref.d.ts +9 -6
  170. package/dist/core/codegen/schemas/recursive-ref.d.ts.map +1 -1
  171. package/dist/core/codegen/schemas/recursive-ref.js +44 -44
  172. package/dist/core/codegen/schemas/recursive-ref.js.map +1 -1
  173. package/dist/core/codegen/schemas/set.d.ts +8 -5
  174. package/dist/core/codegen/schemas/set.d.ts.map +1 -1
  175. package/dist/core/codegen/schemas/set.js +61 -73
  176. package/dist/core/codegen/schemas/set.js.map +1 -1
  177. package/dist/core/codegen/schemas/string-bool.d.ts +6 -3
  178. package/dist/core/codegen/schemas/string-bool.d.ts.map +1 -1
  179. package/dist/core/codegen/schemas/string-bool.js +22 -23
  180. package/dist/core/codegen/schemas/string-bool.js.map +1 -1
  181. package/dist/core/codegen/schemas/string.d.ts +8 -5
  182. package/dist/core/codegen/schemas/string.d.ts.map +1 -1
  183. package/dist/core/codegen/schemas/string.js +168 -207
  184. package/dist/core/codegen/schemas/string.js.map +1 -1
  185. package/dist/core/codegen/schemas/symbol.d.ts +7 -4
  186. package/dist/core/codegen/schemas/symbol.d.ts.map +1 -1
  187. package/dist/core/codegen/schemas/symbol.js +8 -4
  188. package/dist/core/codegen/schemas/symbol.js.map +1 -1
  189. package/dist/core/codegen/schemas/template-literal.d.ts +7 -4
  190. package/dist/core/codegen/schemas/template-literal.d.ts.map +1 -1
  191. package/dist/core/codegen/schemas/template-literal.js +12 -13
  192. package/dist/core/codegen/schemas/template-literal.js.map +1 -1
  193. package/dist/core/codegen/schemas/tuple.d.ts +8 -5
  194. package/dist/core/codegen/schemas/tuple.d.ts.map +1 -1
  195. package/dist/core/codegen/schemas/tuple.js +84 -94
  196. package/dist/core/codegen/schemas/tuple.js.map +1 -1
  197. package/dist/core/codegen/schemas/undefined.d.ts +7 -4
  198. package/dist/core/codegen/schemas/undefined.d.ts.map +1 -1
  199. package/dist/core/codegen/schemas/undefined.js +8 -4
  200. package/dist/core/codegen/schemas/undefined.js.map +1 -1
  201. package/dist/core/codegen/schemas/union.d.ts +8 -5
  202. package/dist/core/codegen/schemas/union.d.ts.map +1 -1
  203. package/dist/core/codegen/schemas/union.js +49 -69
  204. package/dist/core/codegen/schemas/union.js.map +1 -1
  205. package/dist/core/codegen/schemas/unknown.d.ts +7 -4
  206. package/dist/core/codegen/schemas/unknown.d.ts.map +1 -1
  207. package/dist/core/codegen/schemas/unknown.js +8 -4
  208. package/dist/core/codegen/schemas/unknown.js.map +1 -1
  209. package/dist/core/codegen/schemas/void.d.ts +7 -4
  210. package/dist/core/codegen/schemas/void.d.ts.map +1 -1
  211. package/dist/core/codegen/schemas/void.js +8 -4
  212. package/dist/core/codegen/schemas/void.js.map +1 -1
  213. package/dist/core/codegen/slow-path.d.ts +7 -4
  214. package/dist/core/codegen/slow-path.d.ts.map +1 -1
  215. package/dist/core/codegen/slow-path.js +71 -96
  216. package/dist/core/codegen/slow-path.js.map +1 -1
  217. package/dist/core/codegen/well-known-regex.d.ts +22 -19
  218. package/dist/core/codegen/well-known-regex.d.ts.map +1 -1
  219. package/dist/core/codegen/well-known-regex.js +127 -96
  220. package/dist/core/codegen/well-known-regex.js.map +1 -1
  221. package/dist/core/compile.d.ts +7 -4
  222. package/dist/core/compile.d.ts.map +1 -1
  223. package/dist/core/compile.js +48 -48
  224. package/dist/core/compile.js.map +1 -1
  225. package/dist/core/diagnostic.d.ts +38 -39
  226. package/dist/core/diagnostic.d.ts.map +1 -1
  227. package/dist/core/diagnostic.js +140 -164
  228. package/dist/core/diagnostic.js.map +1 -1
  229. package/dist/core/extract/checks.d.ts +18 -15
  230. package/dist/core/extract/checks.d.ts.map +1 -1
  231. package/dist/core/extract/checks.js +318 -311
  232. package/dist/core/extract/checks.js.map +1 -1
  233. package/dist/core/extract/effects.d.ts +13 -10
  234. package/dist/core/extract/effects.d.ts.map +1 -1
  235. package/dist/core/extract/effects.js +153 -222
  236. package/dist/core/extract/effects.js.map +1 -1
  237. package/dist/core/extract/extractors/any.d.ts +5 -2
  238. package/dist/core/extract/extractors/any.d.ts.map +1 -1
  239. package/dist/core/extract/extractors/any.js +5 -1
  240. package/dist/core/extract/extractors/any.js.map +1 -1
  241. package/dist/core/extract/extractors/array.d.ts +6 -3
  242. package/dist/core/extract/extractors/array.d.ts.map +1 -1
  243. package/dist/core/extract/extractors/array.js +25 -20
  244. package/dist/core/extract/extractors/array.js.map +1 -1
  245. package/dist/core/extract/extractors/bigint.d.ts +6 -3
  246. package/dist/core/extract/extractors/bigint.d.ts.map +1 -1
  247. package/dist/core/extract/extractors/bigint.js +66 -64
  248. package/dist/core/extract/extractors/bigint.js.map +1 -1
  249. package/dist/core/extract/extractors/boolean.d.ts +5 -2
  250. package/dist/core/extract/extractors/boolean.d.ts.map +1 -1
  251. package/dist/core/extract/extractors/boolean.js +7 -3
  252. package/dist/core/extract/extractors/boolean.js.map +1 -1
  253. package/dist/core/extract/extractors/catch.d.ts +6 -3
  254. package/dist/core/extract/extractors/catch.d.ts.map +1 -1
  255. package/dist/core/extract/extractors/catch.js +26 -17
  256. package/dist/core/extract/extractors/catch.js.map +1 -1
  257. package/dist/core/extract/extractors/date.d.ts +6 -3
  258. package/dist/core/extract/extractors/date.d.ts.map +1 -1
  259. package/dist/core/extract/extractors/date.js +42 -46
  260. package/dist/core/extract/extractors/date.js.map +1 -1
  261. package/dist/core/extract/extractors/default.d.ts +6 -3
  262. package/dist/core/extract/extractors/default.d.ts.map +1 -1
  263. package/dist/core/extract/extractors/default.js +20 -14
  264. package/dist/core/extract/extractors/default.js.map +1 -1
  265. package/dist/core/extract/extractors/enum.d.ts +5 -2
  266. package/dist/core/extract/extractors/enum.d.ts.map +1 -1
  267. package/dist/core/extract/extractors/enum.js +12 -13
  268. package/dist/core/extract/extractors/enum.js.map +1 -1
  269. package/dist/core/extract/extractors/file.d.ts +6 -3
  270. package/dist/core/extract/extractors/file.d.ts.map +1 -1
  271. package/dist/core/extract/extractors/file.js +34 -28
  272. package/dist/core/extract/extractors/file.js.map +1 -1
  273. package/dist/core/extract/extractors/intersection.d.ts +5 -2
  274. package/dist/core/extract/extractors/intersection.d.ts.map +1 -1
  275. package/dist/core/extract/extractors/intersection.js +13 -11
  276. package/dist/core/extract/extractors/intersection.js.map +1 -1
  277. package/dist/core/extract/extractors/lazy.d.ts +6 -3
  278. package/dist/core/extract/extractors/lazy.d.ts.map +1 -1
  279. package/dist/core/extract/extractors/lazy.js +21 -30
  280. package/dist/core/extract/extractors/lazy.js.map +1 -1
  281. package/dist/core/extract/extractors/literal.d.ts +5 -2
  282. package/dist/core/extract/extractors/literal.d.ts.map +1 -1
  283. package/dist/core/extract/extractors/literal.js +8 -1
  284. package/dist/core/extract/extractors/literal.js.map +1 -1
  285. package/dist/core/extract/extractors/map.d.ts +6 -3
  286. package/dist/core/extract/extractors/map.d.ts.map +1 -1
  287. package/dist/core/extract/extractors/map.js +10 -4
  288. package/dist/core/extract/extractors/map.js.map +1 -1
  289. package/dist/core/extract/extractors/nan.d.ts +5 -2
  290. package/dist/core/extract/extractors/nan.d.ts.map +1 -1
  291. package/dist/core/extract/extractors/nan.js +5 -1
  292. package/dist/core/extract/extractors/nan.js.map +1 -1
  293. package/dist/core/extract/extractors/never.d.ts +5 -2
  294. package/dist/core/extract/extractors/never.d.ts.map +1 -1
  295. package/dist/core/extract/extractors/never.js +5 -1
  296. package/dist/core/extract/extractors/never.js.map +1 -1
  297. package/dist/core/extract/extractors/null.d.ts +5 -2
  298. package/dist/core/extract/extractors/null.d.ts.map +1 -1
  299. package/dist/core/extract/extractors/null.js +5 -1
  300. package/dist/core/extract/extractors/null.js.map +1 -1
  301. package/dist/core/extract/extractors/nullable.d.ts +5 -2
  302. package/dist/core/extract/extractors/nullable.d.ts.map +1 -1
  303. package/dist/core/extract/extractors/nullable.js +7 -3
  304. package/dist/core/extract/extractors/nullable.js.map +1 -1
  305. package/dist/core/extract/extractors/number.d.ts +6 -3
  306. package/dist/core/extract/extractors/number.d.ts.map +1 -1
  307. package/dist/core/extract/extractors/number.js +35 -35
  308. package/dist/core/extract/extractors/number.js.map +1 -1
  309. package/dist/core/extract/extractors/object.d.ts +6 -3
  310. package/dist/core/extract/extractors/object.d.ts.map +1 -1
  311. package/dist/core/extract/extractors/object.js +49 -76
  312. package/dist/core/extract/extractors/object.js.map +1 -1
  313. package/dist/core/extract/extractors/optional.d.ts +5 -2
  314. package/dist/core/extract/extractors/optional.d.ts.map +1 -1
  315. package/dist/core/extract/extractors/optional.js +10 -12
  316. package/dist/core/extract/extractors/optional.js.map +1 -1
  317. package/dist/core/extract/extractors/pipe.d.ts +6 -3
  318. package/dist/core/extract/extractors/pipe.d.ts.map +1 -1
  319. package/dist/core/extract/extractors/pipe.js +40 -41
  320. package/dist/core/extract/extractors/pipe.js.map +1 -1
  321. package/dist/core/extract/extractors/readonly.d.ts +5 -2
  322. package/dist/core/extract/extractors/readonly.d.ts.map +1 -1
  323. package/dist/core/extract/extractors/readonly.js +10 -6
  324. package/dist/core/extract/extractors/readonly.js.map +1 -1
  325. package/dist/core/extract/extractors/record.d.ts +6 -3
  326. package/dist/core/extract/extractors/record.d.ts.map +1 -1
  327. package/dist/core/extract/extractors/record.js +24 -35
  328. package/dist/core/extract/extractors/record.js.map +1 -1
  329. package/dist/core/extract/extractors/set.d.ts +6 -3
  330. package/dist/core/extract/extractors/set.d.ts.map +1 -1
  331. package/dist/core/extract/extractors/set.js +36 -30
  332. package/dist/core/extract/extractors/set.js.map +1 -1
  333. package/dist/core/extract/extractors/string-bool.d.ts +7 -4
  334. package/dist/core/extract/extractors/string-bool.d.ts.map +1 -1
  335. package/dist/core/extract/extractors/string-bool.js +66 -84
  336. package/dist/core/extract/extractors/string-bool.js.map +1 -1
  337. package/dist/core/extract/extractors/string.d.ts +6 -3
  338. package/dist/core/extract/extractors/string.d.ts.map +1 -1
  339. package/dist/core/extract/extractors/string.js +34 -37
  340. package/dist/core/extract/extractors/string.js.map +1 -1
  341. package/dist/core/extract/extractors/symbol.d.ts +5 -2
  342. package/dist/core/extract/extractors/symbol.d.ts.map +1 -1
  343. package/dist/core/extract/extractors/symbol.js +5 -1
  344. package/dist/core/extract/extractors/symbol.js.map +1 -1
  345. package/dist/core/extract/extractors/template-literal.d.ts +6 -3
  346. package/dist/core/extract/extractors/template-literal.d.ts.map +1 -1
  347. package/dist/core/extract/extractors/template-literal.js +11 -6
  348. package/dist/core/extract/extractors/template-literal.js.map +1 -1
  349. package/dist/core/extract/extractors/tuple.d.ts +6 -3
  350. package/dist/core/extract/extractors/tuple.d.ts.map +1 -1
  351. package/dist/core/extract/extractors/tuple.js +10 -4
  352. package/dist/core/extract/extractors/tuple.js.map +1 -1
  353. package/dist/core/extract/extractors/undefined.d.ts +5 -2
  354. package/dist/core/extract/extractors/undefined.d.ts.map +1 -1
  355. package/dist/core/extract/extractors/undefined.js +5 -1
  356. package/dist/core/extract/extractors/undefined.js.map +1 -1
  357. package/dist/core/extract/extractors/union.d.ts +6 -3
  358. package/dist/core/extract/extractors/union.d.ts.map +1 -1
  359. package/dist/core/extract/extractors/union.js +38 -64
  360. package/dist/core/extract/extractors/union.js.map +1 -1
  361. package/dist/core/extract/extractors/unknown.d.ts +5 -2
  362. package/dist/core/extract/extractors/unknown.d.ts.map +1 -1
  363. package/dist/core/extract/extractors/unknown.js +5 -1
  364. package/dist/core/extract/extractors/unknown.js.map +1 -1
  365. package/dist/core/extract/extractors/void.d.ts +5 -2
  366. package/dist/core/extract/extractors/void.d.ts.map +1 -1
  367. package/dist/core/extract/extractors/void.js +5 -1
  368. package/dist/core/extract/extractors/void.js.map +1 -1
  369. package/dist/core/extract/fallback.d.ts +6 -3
  370. package/dist/core/extract/fallback.d.ts.map +1 -1
  371. package/dist/core/extract/fallback.js +21 -7
  372. package/dist/core/extract/fallback.js.map +1 -1
  373. package/dist/core/extract/index.d.ts +6 -4
  374. package/dist/core/extract/index.d.ts.map +1 -1
  375. package/dist/core/extract/index.js +15 -15
  376. package/dist/core/extract/index.js.map +1 -1
  377. package/dist/core/extract/registry.d.ts +39 -36
  378. package/dist/core/extract/registry.d.ts.map +1 -1
  379. package/dist/core/extract/registry.js +96 -123
  380. package/dist/core/extract/registry.js.map +1 -1
  381. package/dist/core/extract/types.d.ts +124 -120
  382. package/dist/core/extract/types.d.ts.map +1 -1
  383. package/dist/core/extract/types.js +0 -1
  384. package/dist/core/iife.d.ts +14 -15
  385. package/dist/core/iife.d.ts.map +1 -1
  386. package/dist/core/iife.js +182 -206
  387. package/dist/core/iife.js.map +1 -1
  388. package/dist/core/pipeline.d.ts +33 -30
  389. package/dist/core/pipeline.d.ts.map +1 -1
  390. package/dist/core/pipeline.js +67 -74
  391. package/dist/core/pipeline.js.map +1 -1
  392. package/dist/core/types.d.ts +430 -427
  393. package/dist/core/types.d.ts.map +1 -1
  394. package/dist/core/types.js +0 -5
  395. package/dist/discovery.d.ts +8 -5
  396. package/dist/discovery.d.ts.map +1 -1
  397. package/dist/discovery.js +31 -32
  398. package/dist/discovery.js.map +1 -1
  399. package/dist/index.d.ts +4 -4
  400. package/dist/index.js +2 -2
  401. package/dist/jit.d.ts +15 -42
  402. package/dist/jit.d.ts.map +1 -1
  403. package/dist/jit.js +187 -216
  404. package/dist/jit.js.map +1 -1
  405. package/dist/loader.d.ts +14 -11
  406. package/dist/loader.d.ts.map +1 -1
  407. package/dist/loader.js +226 -258
  408. package/dist/loader.js.map +1 -1
  409. package/dist/static-filter.d.ts +4 -1
  410. package/dist/static-filter.d.ts.map +1 -1
  411. package/dist/static-filter.js +240 -367
  412. package/dist/static-filter.js.map +1 -1
  413. package/dist/swc.d.ts +38 -35
  414. package/dist/swc.d.ts.map +1 -1
  415. package/dist/swc.js +83 -76
  416. package/dist/swc.js.map +1 -1
  417. package/dist/unplugin/bun.d.ts +5 -2
  418. package/dist/unplugin/bun.d.ts.map +1 -1
  419. package/dist/unplugin/bun.js +5 -1
  420. package/dist/unplugin/bun.js.map +1 -1
  421. package/dist/unplugin/dep-graph.d.ts +10 -7
  422. package/dist/unplugin/dep-graph.d.ts.map +1 -1
  423. package/dist/unplugin/dep-graph.js +216 -252
  424. package/dist/unplugin/dep-graph.js.map +1 -1
  425. package/dist/unplugin/disk-cache.d.ts +121 -92
  426. package/dist/unplugin/disk-cache.d.ts.map +1 -1
  427. package/dist/unplugin/disk-cache.js +425 -444
  428. package/dist/unplugin/disk-cache.js.map +1 -1
  429. package/dist/unplugin/edits.d.ts +15 -12
  430. package/dist/unplugin/edits.d.ts.map +1 -1
  431. package/dist/unplugin/edits.js +24 -37
  432. package/dist/unplugin/edits.js.map +1 -1
  433. package/dist/unplugin/esbuild.d.ts +5 -2
  434. package/dist/unplugin/esbuild.d.ts.map +1 -1
  435. package/dist/unplugin/esbuild.js +5 -1
  436. package/dist/unplugin/esbuild.js.map +1 -1
  437. package/dist/unplugin/farm.d.ts +5 -2
  438. package/dist/unplugin/farm.d.ts.map +1 -1
  439. package/dist/unplugin/farm.js +5 -1
  440. package/dist/unplugin/farm.js.map +1 -1
  441. package/dist/unplugin/hoist-compile.d.ts +14 -42
  442. package/dist/unplugin/hoist-compile.d.ts.map +1 -1
  443. package/dist/unplugin/hoist-compile.js +67 -112
  444. package/dist/unplugin/hoist-compile.js.map +1 -1
  445. package/dist/unplugin/hoist.d.ts +56 -54
  446. package/dist/unplugin/hoist.d.ts.map +1 -1
  447. package/dist/unplugin/hoist.js +945 -1170
  448. package/dist/unplugin/hoist.js.map +1 -1
  449. package/dist/unplugin/index.d.ts +5 -3
  450. package/dist/unplugin/index.d.ts.map +1 -1
  451. package/dist/unplugin/index.js +175 -250
  452. package/dist/unplugin/index.js.map +1 -1
  453. package/dist/unplugin/rolldown.d.ts +5 -2
  454. package/dist/unplugin/rolldown.d.ts.map +1 -1
  455. package/dist/unplugin/rolldown.js +5 -1
  456. package/dist/unplugin/rolldown.js.map +1 -1
  457. package/dist/unplugin/rollup.d.ts +5 -2
  458. package/dist/unplugin/rollup.d.ts.map +1 -1
  459. package/dist/unplugin/rollup.js +5 -1
  460. package/dist/unplugin/rollup.js.map +1 -1
  461. package/dist/unplugin/rsbuild.d.ts +6 -3
  462. package/dist/unplugin/rsbuild.d.ts.map +1 -1
  463. package/dist/unplugin/rsbuild.js +15 -11
  464. package/dist/unplugin/rsbuild.js.map +1 -1
  465. package/dist/unplugin/rspack.d.ts +5 -2
  466. package/dist/unplugin/rspack.d.ts.map +1 -1
  467. package/dist/unplugin/rspack.js +5 -1
  468. package/dist/unplugin/rspack.js.map +1 -1
  469. package/dist/unplugin/transform.d.ts +30 -27
  470. package/dist/unplugin/transform.d.ts.map +1 -1
  471. package/dist/unplugin/transform.js +433 -620
  472. package/dist/unplugin/transform.js.map +1 -1
  473. package/dist/unplugin/types.d.ts +189 -184
  474. package/dist/unplugin/types.d.ts.map +1 -1
  475. package/dist/unplugin/types.js +22 -18
  476. package/dist/unplugin/types.js.map +1 -1
  477. package/dist/unplugin/virtual.d.ts +11 -8
  478. package/dist/unplugin/virtual.d.ts.map +1 -1
  479. package/dist/unplugin/virtual.js +65 -83
  480. package/dist/unplugin/virtual.js.map +1 -1
  481. package/dist/unplugin/vite.d.ts +5 -2
  482. package/dist/unplugin/vite.d.ts.map +1 -1
  483. package/dist/unplugin/vite.js +5 -1
  484. package/dist/unplugin/vite.js.map +1 -1
  485. package/dist/unplugin/webpack.d.ts +5 -2
  486. package/dist/unplugin/webpack.d.ts.map +1 -1
  487. package/dist/unplugin/webpack.js +5 -1
  488. package/dist/unplugin/webpack.js.map +1 -1
  489. package/package.json +23 -14
  490. package/dist/cli/index.d.ts.map +0 -1
  491. package/dist/core/extract/types.js.map +0 -1
  492. package/dist/core/types.js.map +0 -1
  493. package/dist/index.d.ts.map +0 -1
  494. package/dist/index.js.map +0 -1
@@ -1,205 +1,180 @@
1
- import { declareFastTemps, emitConstant, escapeString, extendPath, hasMutation, literalToJs, } from "../context.js";
1
+ import { declareFastTemps, emitConstant, escapeString, extendPath, hasMutation, literalToJs } from "../context.js";
2
2
  import { emit } from "../emit.js";
3
3
  import { invalidType } from "../emit-issue.js";
4
- export function slowDiscriminatedUnion(ir, g) {
5
- const discKey = escapeString(ir.discriminator);
6
- let code = emit `
4
+ //#region src/core/codegen/schemas/discriminated-union.ts
5
+ function slowDiscriminatedUnion(ir, g) {
6
+ const discKey = escapeString(ir.discriminator);
7
+ let code = emit`
7
8
  if(typeof ${g.input}!=="object"||${g.input}===null||Array.isArray(${g.input})){
8
9
  ${invalidType(g, "object")}
9
10
  }else{`;
10
- const objVar = g.temp("du");
11
- code += `var ${objVar}=${g.input};switch(${objVar}[${discKey}]){`;
12
- for (const { value, option: index } of ir.cases) {
13
- const option = ir.options[index];
14
- code += emit `
11
+ const objVar = g.temp("du");
12
+ code += `var ${objVar}=${g.input};switch(${objVar}[${discKey}]){`;
13
+ for (const { value, option: index } of ir.cases) {
14
+ const option = ir.options[index];
15
+ code += emit`
15
16
  case ${literalToJs(value)}:
16
- ${g.visit(option, { input: objVar, output: objVar })}
17
+ ${g.visit(option, {
18
+ input: objVar,
19
+ output: objVar
20
+ })}
17
21
  break;`;
18
- }
19
- const validValues = ir.cases.map((c) => literalToJs(c.value)).join(",");
20
- const msgProp = g.typeMsg === undefined ? "" : `,message:${JSON.stringify(g.typeMsg)}`;
21
- code += emit `
22
+ }
23
+ const validValues = ir.cases.map((c) => literalToJs(c.value)).join(",");
24
+ const msgProp = g.typeMsg === void 0 ? "" : `,message:${JSON.stringify(g.typeMsg)}`;
25
+ code += emit`
22
26
  default:
23
27
  ${g.issues}.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:${discKey},options:[${validValues}]${msgProp},input:${g.input},path:${extendPath(g.path, discKey)}});
24
28
  }`;
25
- // Propagate option-applied mutations (defaults, coercions, transforms,
26
- // overwrite checks, stringbool) back to the output location. Each option is
27
- // visited with output:objVar — a fresh local — so a mutating option's clone is
28
- // reassigned into objVar and stranded there; without this write-back the caller
29
- // returns the ORIGINAL input by reference and the mutation is silently lost.
30
- // Gated on mutation so a pure-validation union stays a zero-write pass-through
31
- // (objVar still aliases the input). On the no-match/failure paths objVar equals
32
- // the input, so the write is a harmless self-assignment.
33
- if (ir.options.some(hasMutation)) {
34
- code += `${g.output}=${objVar};`;
35
- }
36
- code += `}`;
37
- return `${code}\n`;
29
+ if (ir.options.some(hasMutation)) code += `${g.output}=${objVar};`;
30
+ code += `}`;
31
+ return `${code}\n`;
38
32
  }
39
33
  /**
40
- * Emit an O(1) switch-dispatch fast-check for a discriminated union — real
41
- * (`z.discriminatedUnion`) or one detected inside a plain `z.union`
42
- * (see {@link detectUnionDiscriminator}). Both share this so the detected case
43
- * inherits the size-gating and the per-case guard strip.
44
- *
45
- * `discSkipKey` tells each object option to drop its own type-guard and
46
- * discriminator re-check: the caller's guard (`typeof x==="object"&&…` below)
47
- * already proved object-ness, and the matched switch case has fixed the
48
- * discriminator value, so re-emitting either is pure redundancy the optimizer
49
- * only removes when it inlines this helper — which a union large enough to
50
- * matter won't. Routed through the normal `visit` so size-gated extraction
51
- * still bounds the switch (the strip survives into any hoisted helper);
52
- * non-object options ignore the hint and keep their own guard.
53
- *
54
- * Returns null if any option is fast-path-ineligible.
55
- */
56
- export function emitFastDiscriminatedSwitch(g, discriminator, cases, options) {
57
- const x = g.input;
58
- const discKey = escapeString(discriminator);
59
- const helperName = g.temp("du");
60
- const helperParam = g.temp("dx");
61
- // The switch body is its own function: size-gate the options against the cap
62
- // in a fresh scope, otherwise many small options accumulate into the caller's
63
- // scope while this helper itself grows unbounded past the TurboFan budget.
64
- const body = g.scoped(helperParam);
65
- const table = stringDispatchTable(cases);
66
- if (table === null) {
67
- const caseStrs = [];
68
- for (const { value, option: index } of cases) {
69
- const check = body.visit(options[index], { discSkipKey: discriminator });
70
- if (check === null)
71
- return null;
72
- caseStrs.push(`case ${literalToJs(value)}:return ${check};`);
73
- }
74
- g.ctx.preamble.push(`function ${helperName}(${helperParam}){${declareFastTemps(body.scope)}switch(${helperParam}[${discKey}]){${caseStrs.join("")}default:return false;}}`);
75
- }
76
- else {
77
- // Dispatch through a string→ordinal table, then switch on the ordinal. V8
78
- // compiles a switch over STRING labels as sequential `===` comparisons, so
79
- // the plain form costs ~0.5 ns per preceding case: measured 4.1 ns (2
80
- // variants), 11.4 (8), 52.1 (80). A dense integer switch becomes a jump
81
- // table, leaving the lookup flat — 5.9 ns (8) and 15.1 (80), i.e. 1.9x to
82
- // 3.5x, for a table that adds ~1.3% to a union's generated bytes.
83
- //
84
- // `typeof t==="string"` is load-bearing: property access would coerce a
85
- // non-string discriminator (an object's toString, a number) into a key that
86
- // could hit a case whose own discriminator check the switch has stripped.
87
- // Strict equality never matched those, so the guard keeps the verdict.
88
- const caseStrs = [];
89
- for (const [optionIndex, ordinal] of table.ordinals) {
90
- const check = body.visit(options[optionIndex], { discSkipKey: discriminator });
91
- if (check === null)
92
- return null;
93
- caseStrs.push(`case ${ordinal}:return ${check};`);
94
- }
95
- const tableVar = emitConstant(g.ctx, "dt", table.initializer);
96
- const t = g.temp("dv");
97
- g.ctx.preamble.push(`function ${helperName}(${helperParam}){${declareFastTemps(body.scope)}var ${t}=${helperParam}[${discKey}];` +
98
- `switch(typeof ${t}==="string"?${tableVar}[${t}]:0){${caseStrs.join("")}default:return false;}}`);
99
- }
100
- return `typeof ${x}==="object"&&${x}!==null&&!Array.isArray(${x})&&${helperName}(${x})`;
34
+ * Emit an O(1) switch-dispatch fast-check for a discriminated union — real
35
+ * (`z.discriminatedUnion`) or one detected inside a plain `z.union`
36
+ * (see {@link detectUnionDiscriminator}). Both share this so the detected case
37
+ * inherits the size-gating and the per-case guard strip.
38
+ *
39
+ * `discSkipKey` tells each object option to drop its own type-guard and
40
+ * discriminator re-check: the caller's guard (`typeof x==="object"&&…` below)
41
+ * already proved object-ness, and the matched switch case has fixed the
42
+ * discriminator value, so re-emitting either is pure redundancy the optimizer
43
+ * only removes when it inlines this helper — which a union large enough to
44
+ * matter won't. Routed through the normal `visit` so size-gated extraction
45
+ * still bounds the switch (the strip survives into any hoisted helper);
46
+ * non-object options ignore the hint and keep their own guard.
47
+ *
48
+ * Returns null if any option is fast-path-ineligible.
49
+ */
50
+ function emitFastDiscriminatedSwitch(g, discriminator, cases, options) {
51
+ const x = g.input;
52
+ const discKey = escapeString(discriminator);
53
+ const helperName = g.temp("du");
54
+ const helperParam = g.temp("dx");
55
+ const body = g.scoped(helperParam);
56
+ const table = stringDispatchTable(cases);
57
+ if (table === null) {
58
+ const caseStrs = [];
59
+ for (const { value, option: index } of cases) {
60
+ const check = body.visit(options[index], { discSkipKey: discriminator });
61
+ if (check === null) return null;
62
+ caseStrs.push(`case ${literalToJs(value)}:return ${check};`);
63
+ }
64
+ g.ctx.preamble.push(`function ${helperName}(${helperParam}){${declareFastTemps(body.scope)}switch(${helperParam}[${discKey}]){${caseStrs.join("")}default:return false;}}`);
65
+ } else {
66
+ const caseStrs = [];
67
+ for (const [optionIndex, ordinal] of table.ordinals) {
68
+ const check = body.visit(options[optionIndex], { discSkipKey: discriminator });
69
+ if (check === null) return null;
70
+ caseStrs.push(`case ${ordinal}:return ${check};`);
71
+ }
72
+ const tableVar = emitConstant(g.ctx, "dt", table.initializer);
73
+ const t = g.temp("dv");
74
+ g.ctx.preamble.push(`function ${helperName}(${helperParam}){${declareFastTemps(body.scope)}var ${t}=${helperParam}[${discKey}];switch(typeof ${t}==="string"?${tableVar}[${t}]:0){${caseStrs.join("")}default:return false;}}`);
75
+ }
76
+ return `typeof ${x}==="object"&&${x}!==null&&!Array.isArray(${x})&&${helperName}(${x})`;
101
77
  }
102
78
  /**
103
- * Minimum case count for ordinal dispatch. Measured crossover is 3: at 2 cases
104
- * the string switch is one comparison and beats the extra table lookup
105
- * (4.1 ns vs 4.5), at 3 the table already wins (6.1 vs 4.6).
106
- */
79
+ * Minimum case count for ordinal dispatch. Measured crossover is 3: at 2 cases
80
+ * the string switch is one comparison and beats the extra table lookup
81
+ * (4.1 ns vs 4.5), at 3 the table already wins (6.1 vs 4.6).
82
+ */
107
83
  const MIN_TABLE_DISPATCH = 3;
108
84
  /**
109
- * Build the `{value: ordinal}` dispatch table for a set of cases, or null when
110
- * the plain string switch should be kept. Requires every discriminator value to
111
- * be a string — mixed types would collide once coerced to property keys (`5`
112
- * and `"5"`) — and excludes `__proto__`, which an object literal cannot hold as
113
- * an own key. Values that select the SAME option share one ordinal, so a
114
- * multi-value literal emits its check once instead of per value.
115
- */
85
+ * Build the `{value: ordinal}` dispatch table for a set of cases, or null when
86
+ * the plain string switch should be kept. Requires every discriminator value to
87
+ * be a string — mixed types would collide once coerced to property keys (`5`
88
+ * and `"5"`) — and excludes `__proto__`, which an object literal cannot hold as
89
+ * an own key. Values that select the SAME option share one ordinal, so a
90
+ * multi-value literal emits its check once instead of per value.
91
+ */
116
92
  function stringDispatchTable(cases) {
117
- if (cases.length < MIN_TABLE_DISPATCH)
118
- return null;
119
- if (!cases.every((c) => typeof c.value === "string" && c.value !== "__proto__"))
120
- return null;
121
- const ordinals = new Map();
122
- const entries = [];
123
- for (const { value, option } of cases) {
124
- let ordinal = ordinals.get(option);
125
- if (ordinal === undefined) {
126
- ordinal = ordinals.size + 1;
127
- ordinals.set(option, ordinal);
128
- }
129
- entries.push(`${escapeString(value)}:${ordinal}`);
130
- }
131
- return { initializer: `{${entries.join(",")}}`, ordinals };
93
+ if (cases.length < MIN_TABLE_DISPATCH) return null;
94
+ if (!cases.every((c) => typeof c.value === "string" && c.value !== "__proto__")) return null;
95
+ const ordinals = /* @__PURE__ */ new Map();
96
+ const entries = [];
97
+ for (const { value, option } of cases) {
98
+ let ordinal = ordinals.get(option);
99
+ if (ordinal === void 0) {
100
+ ordinal = ordinals.size + 1;
101
+ ordinals.set(option, ordinal);
102
+ }
103
+ entries.push(`${escapeString(value)}:${ordinal}`);
104
+ }
105
+ return {
106
+ initializer: `{${entries.join(",")}}`,
107
+ ordinals
108
+ };
132
109
  }
133
- export function fastDiscriminatedUnion(ir, g) {
134
- return emitFastDiscriminatedSwitch(g, ir.discriminator, ir.cases, ir.options);
110
+ function fastDiscriminatedUnion(ir, g) {
111
+ return emitFastDiscriminatedSwitch(g, ir.discriminator, ir.cases, ir.options);
135
112
  }
136
113
  /**
137
- * Minimum option count for rewriting a plain `z.union` to switch dispatch. Below
138
- * this the switch helper's fixed call overhead loses to a fully-inlined
139
- * `||`-chain that V8 keeps flat: measured crossover is ~4 options (n=3 can hit
140
- * 0.6x — a regression — while n=5 is 1.27x and n=32 is 2.34x), so 5 captures the
141
- * stable wins with margin and never regresses a small union. Real
142
- * `z.discriminatedUnion` is unaffected — it dispatches via switch by construction
143
- * regardless of size.
144
- */
114
+ * Minimum option count for rewriting a plain `z.union` to switch dispatch. Below
115
+ * this the switch helper's fixed call overhead loses to a fully-inlined
116
+ * `||`-chain that V8 keeps flat: measured crossover is ~4 options (n=3 can hit
117
+ * 0.6x — a regression — while n=5 is 1.27x and n=32 is 2.34x), so 5 captures the
118
+ * stable wins with margin and never regresses a small union. Real
119
+ * `z.discriminatedUnion` is unaffected — it dispatches via switch by construction
120
+ * regardless of size.
121
+ */
145
122
  const MIN_AUTO_DISCRIMINATE_OPTIONS = 5;
146
123
  /** Values that switch correctly under `===` (excludes `undefined` and `NaN`). */
147
124
  function isSwitchableDiscriminant(v) {
148
- return (v === null ||
149
- typeof v === "string" ||
150
- typeof v === "boolean" ||
151
- typeof v === "bigint" ||
152
- (typeof v === "number" && !Number.isNaN(v)));
125
+ return v === null || typeof v === "string" || typeof v === "boolean" || typeof v === "bigint" || typeof v === "number" && !Number.isNaN(v);
153
126
  }
154
127
  /**
155
- * Detect whether a plain (untagged) `z.union` is *structurally* a discriminated
156
- * union, so its fast path can use O(1) switch dispatch instead of probing every
157
- * arm. Returns the discriminator + dispatch table, or null to keep the
158
- * `||`-chain.
159
- *
160
- * Requires (proving the switch accepts exactly what the `||`-chain would): every
161
- * option is a plain object that pins one shared key to a REQUIRED literal
162
- * (`prop.type === "literal"` — an optional/non-literal key is rejected), and the
163
- * literal values are pairwise DISJOINT across options. Disjointness is the crux:
164
- * it guarantees at most one option can accept any given input, so dispatching to
165
- * that single option is equivalent to trying them all. Any value shared by two
166
- * options (ambiguous), a non-switchable value (`undefined`/`NaN`), or a
167
- * non-object option makes detection bail to the safe `||`-chain.
168
- *
169
- * Fast-path only: the slow path keeps `z.union`'s sequential trial and its
170
- * `invalid_union` error shape, so failure output stays byte-identical to Zod.
171
- */
172
- export function detectUnionDiscriminator(options) {
173
- if (options.length < MIN_AUTO_DISCRIMINATE_OPTIONS)
174
- return null;
175
- const objects = [];
176
- for (const option of options) {
177
- if (option.type !== "object")
178
- return null;
179
- objects.push(option);
180
- }
181
- const first = objects[0];
182
- if (first === undefined)
183
- return null; // unreachable (length checked above)
184
- // Only keys present in the first option can be shared by all; try each.
185
- candidate: for (const key of Object.keys(first.properties)) {
186
- const seen = new Set();
187
- const cases = [];
188
- for (const [i, object] of objects.entries()) {
189
- const prop = object.properties[key];
190
- if (prop === undefined || prop.type !== "literal")
191
- continue candidate;
192
- for (const value of prop.values) {
193
- if (!isSwitchableDiscriminant(value))
194
- continue candidate;
195
- if (seen.has(value))
196
- continue candidate; // shared value → ambiguous dispatch
197
- seen.add(value);
198
- cases.push({ value, option: i });
199
- }
200
- }
201
- return { discriminator: key, cases };
202
- }
203
- return null;
128
+ * Detect whether a plain (untagged) `z.union` is *structurally* a discriminated
129
+ * union, so its fast path can use O(1) switch dispatch instead of probing every
130
+ * arm. Returns the discriminator + dispatch table, or null to keep the
131
+ * `||`-chain.
132
+ *
133
+ * Requires (proving the switch accepts exactly what the `||`-chain would): every
134
+ * option is a plain object that pins one shared key to a REQUIRED literal
135
+ * (`prop.type === "literal"` — an optional/non-literal key is rejected), and the
136
+ * literal values are pairwise DISJOINT across options. Disjointness is the crux:
137
+ * it guarantees at most one option can accept any given input, so dispatching to
138
+ * that single option is equivalent to trying them all. Any value shared by two
139
+ * options (ambiguous), a non-switchable value (`undefined`/`NaN`), or a
140
+ * non-object option makes detection bail to the safe `||`-chain.
141
+ *
142
+ * Fast-path only: the slow path keeps `z.union`'s sequential trial and its
143
+ * `invalid_union` error shape, so failure output stays byte-identical to Zod.
144
+ */
145
+ function detectUnionDiscriminator(options) {
146
+ if (options.length < MIN_AUTO_DISCRIMINATE_OPTIONS) return null;
147
+ const objects = [];
148
+ for (const option of options) {
149
+ if (option.type !== "object") return null;
150
+ objects.push(option);
151
+ }
152
+ const first = objects[0];
153
+ if (first === void 0) return null;
154
+ candidate: for (const key of Object.keys(first.properties)) {
155
+ const seen = /* @__PURE__ */ new Set();
156
+ const cases = [];
157
+ for (const [i, object] of objects.entries()) {
158
+ const prop = object.properties[key];
159
+ if (prop === void 0 || prop.type !== "literal") continue candidate;
160
+ for (const value of prop.values) {
161
+ if (!isSwitchableDiscriminant(value)) continue candidate;
162
+ if (seen.has(value)) continue candidate;
163
+ seen.add(value);
164
+ cases.push({
165
+ value,
166
+ option: i
167
+ });
168
+ }
169
+ }
170
+ return {
171
+ discriminator: key,
172
+ cases
173
+ };
174
+ }
175
+ return null;
204
176
  }
177
+ //#endregion
178
+ export { detectUnionDiscriminator, emitFastDiscriminatedSwitch, fastDiscriminatedUnion, slowDiscriminatedUnion };
179
+
205
180
  //# sourceMappingURL=discriminated-union.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"discriminated-union.js","sourceRoot":"","sources":["../../../../src/core/codegen/schemas/discriminated-union.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,WAAW,EACX,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAK/C,MAAM,UAAU,sBAAsB,CACpC,EAA6C,EAC7C,CAAU;IAEV,MAAM,OAAO,GAAG,YAAY,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;IAE/C,IAAI,IAAI,GAAG,IAAI,CAAA;gBACD,CAAC,CAAC,KAAK,gBAAgB,CAAC,CAAC,KAAK,0BAA0B,CAAC,CAAC,KAAK;QACvE,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC;WACrB,CAAC;IAEV,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,IAAI,OAAO,MAAM,IAAI,CAAC,CAAC,KAAK,WAAW,MAAM,IAAI,OAAO,KAAK,CAAC;IAElE,KAAK,M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E,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAChB,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;QACD,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IACvC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
1
+ {"version":3,"file":"discriminated-union.js","names":[],"sources":["../../../../src/core/codegen/schemas/discriminated-union.ts"],"sourcesContent":["import type { DiscriminatedUnionIR, ObjectIR, SchemaIR } from \"../../types.js\";\nimport type { FastGen, SlowGen } from \"../context.js\";\nimport {\n declareFastTemps,\n emitConstant,\n escapeString,\n extendPath,\n hasMutation,\n literalToJs,\n} from \"../context.js\";\nimport { emit } from \"../emit.js\";\nimport { invalidType } from \"../emit-issue.js\";\n\n/** One `discriminator value → option index` dispatch entry. */\ntype DiscriminatorCase = DiscriminatedUnionIR[\"cases\"][number];\n\nexport function slowDiscriminatedUnion(\n ir: SchemaIR & { type: \"discriminatedUnion\" },\n g: SlowGen,\n): string {\n const discKey = escapeString(ir.discriminator);\n\n let code = emit`\n if(typeof ${g.input}!==\"object\"||${g.input}===null||Array.isArray(${g.input})){\n ${invalidType(g, \"object\")}\n }else{`;\n\n const objVar = g.temp(\"du\");\n code += `var ${objVar}=${g.input};switch(${objVar}[${discKey}]){`;\n\n for (const { value, option: index } of ir.cases) {\n const option = ir.options[index] as SchemaIR;\n code += emit`\n case ${literalToJs(value)}:\n ${g.visit(option, { input: objVar, output: objVar })}\n break;`;\n }\n\n const validValues = ir.cases.map((c) => literalToJs(c.value)).join(\",\");\n const msgProp = g.typeMsg === undefined ? \"\" : `,message:${JSON.stringify(g.typeMsg)}`;\n code += emit`\n default:\n ${g.issues}.push({code:\"invalid_union\",errors:[],note:\"No matching discriminator\",discriminator:${discKey},options:[${validValues}]${msgProp},input:${g.input},path:${extendPath(g.path, discKey)}});\n }`;\n // Propagate option-applied mutations (defaults, coercions, transforms,\n // overwrite checks, stringbool) back to the output location. Each option is\n // visited with output:objVar — a fresh local — so a mutating option's clone is\n // reassigned into objVar and stranded there; without this write-back the caller\n // returns the ORIGINAL input by reference and the mutation is silently lost.\n // Gated on mutation so a pure-validation union stays a zero-write pass-through\n // (objVar still aliases the input). On the no-match/failure paths objVar equals\n // the input, so the write is a harmless self-assignment.\n if (ir.options.some(hasMutation)) {\n code += `${g.output}=${objVar};`;\n }\n code += `}`;\n return `${code}\\n`;\n}\n\n/**\n * Emit an O(1) switch-dispatch fast-check for a discriminated union — real\n * (`z.discriminatedUnion`) or one detected inside a plain `z.union`\n * (see {@link detectUnionDiscriminator}). Both share this so the detected case\n * inherits the size-gating and the per-case guard strip.\n *\n * `discSkipKey` tells each object option to drop its own type-guard and\n * discriminator re-check: the caller's guard (`typeof x===\"object\"&&…` below)\n * already proved object-ness, and the matched switch case has fixed the\n * discriminator value, so re-emitting either is pure redundancy the optimizer\n * only removes when it inlines this helper — which a union large enough to\n * matter won't. Routed through the normal `visit` so size-gated extraction\n * still bounds the switch (the strip survives into any hoisted helper);\n * non-object options ignore the hint and keep their own guard.\n *\n * Returns null if any option is fast-path-ineligible.\n */\nexport function emitFastDiscriminatedSwitch(\n g: FastGen,\n discriminator: string,\n cases: readonly DiscriminatorCase[],\n options: readonly SchemaIR[],\n): string | null {\n const x = g.input;\n const discKey = escapeString(discriminator);\n const helperName = g.temp(\"du\");\n const helperParam = g.temp(\"dx\");\n\n // The switch body is its own function: size-gate the options against the cap\n // in a fresh scope, otherwise many small options accumulate into the caller's\n // scope while this helper itself grows unbounded past the TurboFan budget.\n const body = g.scoped(helperParam);\n const table = stringDispatchTable(cases);\n\n if (table === null) {\n const caseStrs: string[] = [];\n for (const { value, option: index } of cases) {\n const check = body.visit(options[index] as SchemaIR, { discSkipKey: discriminator });\n if (check === null) return null;\n caseStrs.push(`case ${literalToJs(value)}:return ${check};`);\n }\n g.ctx.preamble.push(\n `function ${helperName}(${helperParam}){${declareFastTemps(body.scope)}switch(${helperParam}[${discKey}]){${caseStrs.join(\"\")}default:return false;}}`,\n );\n } else {\n // Dispatch through a string→ordinal table, then switch on the ordinal. V8\n // compiles a switch over STRING labels as sequential `===` comparisons, so\n // the plain form costs ~0.5 ns per preceding case: measured 4.1 ns (2\n // variants), 11.4 (8), 52.1 (80). A dense integer switch becomes a jump\n // table, leaving the lookup flat — 5.9 ns (8) and 15.1 (80), i.e. 1.9x to\n // 3.5x, for a table that adds ~1.3% to a union's generated bytes.\n //\n // `typeof t===\"string\"` is load-bearing: property access would coerce a\n // non-string discriminator (an object's toString, a number) into a key that\n // could hit a case whose own discriminator check the switch has stripped.\n // Strict equality never matched those, so the guard keeps the verdict.\n const caseStrs: string[] = [];\n for (const [optionIndex, ordinal] of table.ordinals) {\n const check = body.visit(options[optionIndex] as SchemaIR, { discSkipKey: discriminator });\n if (check === null) return null;\n caseStrs.push(`case ${ordinal}:return ${check};`);\n }\n const tableVar = emitConstant(g.ctx, \"dt\", table.initializer);\n const t = g.temp(\"dv\");\n g.ctx.preamble.push(\n `function ${helperName}(${helperParam}){${declareFastTemps(body.scope)}var ${t}=${helperParam}[${discKey}];` +\n `switch(typeof ${t}===\"string\"?${tableVar}[${t}]:0){${caseStrs.join(\"\")}default:return false;}}`,\n );\n }\n\n return `typeof ${x}===\"object\"&&${x}!==null&&!Array.isArray(${x})&&${helperName}(${x})`;\n}\n\n/**\n * Minimum case count for ordinal dispatch. Measured crossover is 3: at 2 cases\n * the string switch is one comparison and beats the extra table lookup\n * (4.1 ns vs 4.5), at 3 the table already wins (6.1 vs 4.6).\n */\nconst MIN_TABLE_DISPATCH = 3;\n\n/**\n * Build the `{value: ordinal}` dispatch table for a set of cases, or null when\n * the plain string switch should be kept. Requires every discriminator value to\n * be a string — mixed types would collide once coerced to property keys (`5`\n * and `\"5\"`) — and excludes `__proto__`, which an object literal cannot hold as\n * an own key. Values that select the SAME option share one ordinal, so a\n * multi-value literal emits its check once instead of per value.\n */\nfunction stringDispatchTable(\n cases: readonly DiscriminatorCase[],\n): { initializer: string; ordinals: Map<number, number> } | null {\n if (cases.length < MIN_TABLE_DISPATCH) return null;\n if (!cases.every((c) => typeof c.value === \"string\" && c.value !== \"__proto__\")) return null;\n\n const ordinals = new Map<number, number>();\n const entries: string[] = [];\n for (const { value, option } of cases) {\n let ordinal = ordinals.get(option);\n if (ordinal === undefined) {\n ordinal = ordinals.size + 1;\n ordinals.set(option, ordinal);\n }\n entries.push(`${escapeString(value as string)}:${ordinal}`);\n }\n return { initializer: `{${entries.join(\",\")}}`, ordinals };\n}\n\nexport function fastDiscriminatedUnion(ir: DiscriminatedUnionIR, g: FastGen): string | null {\n return emitFastDiscriminatedSwitch(g, ir.discriminator, ir.cases, ir.options);\n}\n\n/**\n * Minimum option count for rewriting a plain `z.union` to switch dispatch. Below\n * this the switch helper's fixed call overhead loses to a fully-inlined\n * `||`-chain that V8 keeps flat: measured crossover is ~4 options (n=3 can hit\n * 0.6x — a regression — while n=5 is 1.27x and n=32 is 2.34x), so 5 captures the\n * stable wins with margin and never regresses a small union. Real\n * `z.discriminatedUnion` is unaffected — it dispatches via switch by construction\n * regardless of size.\n */\nconst MIN_AUTO_DISCRIMINATE_OPTIONS = 5;\n\n/** Values that switch correctly under `===` (excludes `undefined` and `NaN`). */\nfunction isSwitchableDiscriminant(\n v: string | number | boolean | null | bigint | undefined,\n): v is string | number | boolean | bigint | null {\n return (\n v === null ||\n typeof v === \"string\" ||\n typeof v === \"boolean\" ||\n typeof v === \"bigint\" ||\n (typeof v === \"number\" && !Number.isNaN(v))\n );\n}\n\n/**\n * Detect whether a plain (untagged) `z.union` is *structurally* a discriminated\n * union, so its fast path can use O(1) switch dispatch instead of probing every\n * arm. Returns the discriminator + dispatch table, or null to keep the\n * `||`-chain.\n *\n * Requires (proving the switch accepts exactly what the `||`-chain would): every\n * option is a plain object that pins one shared key to a REQUIRED literal\n * (`prop.type === \"literal\"` — an optional/non-literal key is rejected), and the\n * literal values are pairwise DISJOINT across options. Disjointness is the crux:\n * it guarantees at most one option can accept any given input, so dispatching to\n * that single option is equivalent to trying them all. Any value shared by two\n * options (ambiguous), a non-switchable value (`undefined`/`NaN`), or a\n * non-object option makes detection bail to the safe `||`-chain.\n *\n * Fast-path only: the slow path keeps `z.union`'s sequential trial and its\n * `invalid_union` error shape, so failure output stays byte-identical to Zod.\n */\nexport function detectUnionDiscriminator(\n options: readonly SchemaIR[],\n): { discriminator: string; cases: DiscriminatorCase[] } | null {\n if (options.length < MIN_AUTO_DISCRIMINATE_OPTIONS) return null;\n const objects: ObjectIR[] = [];\n for (const option of options) {\n if (option.type !== \"object\") return null;\n objects.push(option);\n }\n const first = objects[0];\n if (first === undefined) return null; // unreachable (length checked above)\n\n // Only keys present in the first option can be shared by all; try each.\n candidate: for (const key of Object.keys(first.properties)) {\n const seen = new Set<string | number | boolean | bigint | null>();\n const cases: DiscriminatorCase[] = [];\n for (const [i, object] of objects.entries()) {\n const prop = object.properties[key];\n if (prop === undefined || prop.type !== \"literal\") continue candidate;\n for (const value of prop.values) {\n if (!isSwitchableDiscriminant(value)) continue candidate;\n if (seen.has(value)) continue candidate; // shared value → ambiguous dispatch\n seen.add(value);\n cases.push({ value, option: i });\n }\n }\n return { discriminator: key, cases };\n }\n return null;\n}\n"],"mappings":";;;;AAgBA,SAAgB,uBACd,IACA,GACQ;CACR,MAAM,UAAU,aAAa,GAAG,aAAa;CAE7C,IAAI,OAAO,IAAI;gBACD,EAAE,MAAM,eAAe,EAAE,MAAM,yBAAyB,EAAE,MAAM;QACxE,YAAY,GAAG,QAAQ,EAAE;;CAG/B,MAAM,SAAS,EAAE,KAAK,IAAI;CAC1B,QAAQ,OAAO,OAAO,GAAG,EAAE,MAAM,UAAU,OAAO,GAAG,QAAQ;CAE7D,KAAK,MAAM,EAAE,OAAO,QAAQ,WAAW,GAAG,OAAO;EAC/C,MAAM,SAAS,GAAG,QAAQ;EAC1B,QAAQ,IAAI;aACH,Y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AO,GAAG,OAAO;AAC9E;;;;;;;;;;AAWA,MAAM,gCAAgC;;AAGtC,SAAS,yBACP,GACgD;CAChD,OACE,MAAM,QACN,OAAO,MAAM,YACb,OAAO,MAAM,aACb,OAAO,MAAM,YACZ,OAAO,MAAM,YAAY,CAAC,OAAO,MAAM,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,yBACd,SAC8D;CAC9D,IAAI,QAAQ,SAAS,+BAA+B,OAAO;CAC3D,MAAM,UAAsB,CAAC;CAC7B,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,OAAO,SAAS,UAAU,OAAO;EACrC,QAAQ,KAAK,MAAM;CACrB;CACA,MAAM,QAAQ,QAAQ;CACtB,IAAI,UAAU,KAAA,GAAW,OAAO;CAGhC,WAAW,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,UAAU,GAAG;EAC1D,MAAM,uBAAO,IAAI,IAA+C;EAChE,MAAM,QAA6B,CAAC;EACpC,KAAK,MAAM,CAAC,GAAG,WAAW,QAAQ,QAAQ,GAAG;GAC3C,MAAM,OAAO,OAAO,WAAW;GAC/B,IAAI,SAAS,KAAA,KAAa,KAAK,SAAS,WAAW,SAAS;GAC5D,KAAK,MAAM,SAAS,KAAK,QAAQ;IAC/B,IAAI,CAAC,yBAAyB,KAAK,GAAG,SAAS;IAC/C,IAAI,KAAK,IAAI,KAAK,GAAG,SAAS;IAC9B,KAAK,IAAI,KAAK;IACd,MAAM,KAAK;KAAE;KAAO,QAAQ;IAAE,CAAC;GACjC;EACF;EACA,OAAO;GAAE,eAAe;GAAK;EAAM;CACrC;CACA,OAAO;AACT"}
@@ -1,10 +1,11 @@
1
- import type { RefineEffectCheckIR, SuperRefineEffectCheckIR, TransformEffectIR } from "../../types.js";
2
- import type { FastGen, SlowGen } from "../context.js";
1
+ import { RefineEffectCheckIR, SuperRefineEffectCheckIR, TransformEffectIR } from "../../types.js";
2
+ import { FastGen, SlowGen } from "../context.js";
3
+ //#region src/core/codegen/schemas/effect.d.ts
3
4
  /**
4
5
  * Generate code for a TransformEffectIR node.
5
6
  * Validates the inner schema, then applies the transform function and writes back the result.
6
7
  */
7
- export declare function slowEffect(ir: TransformEffectIR, g: SlowGen): string;
8
+ declare function slowEffect(ir: TransformEffectIR, g: SlowGen): string;
8
9
  /**
9
10
  * Generate code for a RefineEffectCheckIR (inline refine function call).
10
11
  * Called from string/number/object check loops when a refine_effect is encountered.
@@ -13,12 +14,12 @@ export declare function slowEffect(ir: TransformEffectIR, g: SlowGen): string;
13
14
  * @param expr - The expression to validate (may differ from g.input, e.g. objVar in object generators)
14
15
  * @param g - SlowGen context (provides path, issues)
15
16
  */
16
- export declare function refineCheck(check: RefineEffectCheckIR, expr: string, g: SlowGen): string;
17
+ declare function refineCheck(check: RefineEffectCheckIR, expr: string, g: SlowGen): string;
17
18
  /**
18
19
  * Fast-path test for a SuperRefineEffectCheckIR: a boolean term reporting that
19
20
  * the callback added no issue and left the value alone (see ZC_SR_OK_DECL).
20
21
  */
21
- export declare function superRefineFastTest(check: SuperRefineEffectCheckIR, expr: string, g: FastGen): string;
22
+ declare function superRefineFastTest(check: SuperRefineEffectCheckIR, expr: string, g: FastGen): string;
22
23
  /**
23
24
  * Generate code for a SuperRefineEffectCheckIR: call the payload-taking
24
25
  * callback with a synthesized `{ value, issues }` and merge what it collected.
@@ -31,5 +32,7 @@ export declare function superRefineFastTest(check: SuperRefineEffectCheckIR, exp
31
32
  * (the node reports as mutating, see hasMutation), so the write-back lands on
32
33
  * every parse that reaches it — not only on failures.
33
34
  */
34
- export declare function superRefineCheck(check: SuperRefineEffectCheckIR, expr: string, g: SlowGen): string;
35
+ declare function superRefineCheck(check: SuperRefineEffectCheckIR, expr: string, g: SlowGen): string;
36
+ //#endregion
37
+ export { refineCheck, slowEffect, superRefineCheck, superRefineFastTest };
35
38
  //# sourceMappingURL=effect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../../../../src/core/codegen/schemas/effect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAUtD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,iBAAiB,EAAE,CAAC,EAAE,OAAO,GAAG,MAAM,CAgBpE;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,mBAAmB,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,GAAG,MAAM,CAmBxF;AAaD;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,wBAAwB,EAC/B,IAAI,EAAE,MAAM,EACZ,CAAC,EAAE,OAAO,GACT,MAAM,CAIR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,wBAAwB,EAC/B,IAAI,EAAE,MAAM,EACZ,CAAC,EAAE,OAAO,GACT,MAAM,CAUR"}
1
+ {"version":3,"file":"effect.d.ts","names":[],"sources":["../../../../src/core/codegen/schemas/effect.ts"],"mappings":";;;;;;;iBAmBgB,WAAW,IAAI,mBAAmB,GAAG;;;;;;;;;iBA0BrC,YAAY,OAAO,qBAAqB,cAAc,GAAG;;;;;iBAoCzD,oBACd,OAAO,0BACP,cACA,GAAG;;;;;;;;;;;;;iBAmBW,iBACd,OAAO,0BACP,cACA,GAAG"}
@@ -1,19 +1,16 @@
1
- import { emitEffectCallable, emitRuntimeHelper, extendStaticPath, extendStaticPathIndex, } from "../context.js";
1
+ import { emitEffectCallable, emitRuntimeHelper, extendStaticPath, extendStaticPathIndex } from "../context.js";
2
2
  import { emit } from "../emit.js";
3
3
  import { ZC_SR_DECL, ZC_SR_OK_DECL, ZC_SR_RUN_DECL } from "../issue-decls.js";
4
+ //#region src/core/codegen/schemas/effect.ts
4
5
  /**
5
- * Generate code for a TransformEffectIR node.
6
- * Validates the inner schema, then applies the transform function and writes back the result.
7
- */
8
- export function slowEffect(ir, g) {
9
- const beforeVar = g.temp("ib");
10
- const innerCode = g.visit(ir.inner);
11
- // A transform is `inner.transform(fn)` = a pipe(inner, transform): zod's
12
- // handlePipeResult aborts when `inner` produces any issue. Inside a union the
13
- // option must therefore count as aborted even if `inner`'s only issue is a
14
- // non-aborting `custom`/check-level code (mirrors slowPipe's abort branch).
15
- const abortBranch = g.aborted ? `else{${g.aborted}=true;}` : "";
16
- return `${emit `
6
+ * Generate code for a TransformEffectIR node.
7
+ * Validates the inner schema, then applies the transform function and writes back the result.
8
+ */
9
+ function slowEffect(ir, g) {
10
+ const beforeVar = g.temp("ib");
11
+ const innerCode = g.visit(ir.inner);
12
+ const abortBranch = g.aborted ? `else{${g.aborted}=true;}` : "";
13
+ return `${emit`
17
14
  var ${beforeVar}=${g.issues}.length;
18
15
  ${innerCode}
19
16
  if(${g.issues}.length===${beforeVar}){
@@ -22,69 +19,59 @@ export function slowEffect(ir, g) {
22
19
  `}\n`;
23
20
  }
24
21
  /**
25
- * Generate code for a RefineEffectCheckIR (inline refine function call).
26
- * Called from string/number/object check loops when a refine_effect is encountered.
27
- *
28
- * @param check - The refine effect check IR
29
- * @param expr - The expression to validate (may differ from g.input, e.g. objVar in object generators)
30
- * @param g - SlowGen context (provides path, issues)
31
- */
32
- export function refineCheck(check, expr, g) {
33
- // Custom issues are created by the refine check instance, so only the
34
- // refine's own message applies (never the schema-level error). With no
35
- // message baked in, __zcFin applies the locale default ("Invalid input").
36
- const messageProp = check.message === undefined ? "" : `,message:${JSON.stringify(check.message)}`;
37
- // `.refine(fn, { path })` reports against a member of the refined value, so
38
- // the configured segments extend this node's path.
39
- const path = (check.path ?? []).reduce((acc, segment) => typeof segment === "number"
40
- ? extendStaticPathIndex(acc, segment)
41
- : extendStaticPath(acc, segment), g.path);
42
- return emit `
22
+ * Generate code for a RefineEffectCheckIR (inline refine function call).
23
+ * Called from string/number/object check loops when a refine_effect is encountered.
24
+ *
25
+ * @param check - The refine effect check IR
26
+ * @param expr - The expression to validate (may differ from g.input, e.g. objVar in object generators)
27
+ * @param g - SlowGen context (provides path, issues)
28
+ */
29
+ function refineCheck(check, expr, g) {
30
+ const messageProp = check.message === void 0 ? "" : `,message:${JSON.stringify(check.message)}`;
31
+ const path = (check.path ?? []).reduce((acc, segment) => typeof segment === "number" ? extendStaticPathIndex(acc, segment) : extendStaticPath(acc, segment), g.path);
32
+ return emit`
43
33
  if(!${emitEffectCallable(g.ctx, check)}(${expr})){
44
34
  ${g.issues}.push({code:"custom",path:${path}${messageProp},input:${expr}});
45
35
  }`;
46
36
  }
47
37
  /**
48
- * Declare the shared invoker both superRefine helpers call. It is module-local
49
- * rather than an imported helper (lean mode declares it in the runtime module
50
- * beside them), so inline mode must place it in the preamble itself.
51
- */
38
+ * Declare the shared invoker both superRefine helpers call. It is module-local
39
+ * rather than an imported helper (lean mode declares it in the runtime module
40
+ * beside them), so inline mode must place it in the preamble itself.
41
+ */
52
42
  function emitSuperRefineRunner(ctx) {
53
- if (ctx.mode !== "lean" && !ctx.preamble.includes(ZC_SR_RUN_DECL)) {
54
- ctx.preamble.push(ZC_SR_RUN_DECL);
55
- }
43
+ if (ctx.mode !== "lean" && !ctx.preamble.includes("function __zcSrRun(f,p){var r=f(p);if(r&&typeof r.then===\"function\"){throw new __zcCore.$ZodAsyncError();}}")) ctx.preamble.push(ZC_SR_RUN_DECL);
56
44
  }
57
45
  /**
58
- * Fast-path test for a SuperRefineEffectCheckIR: a boolean term reporting that
59
- * the callback added no issue and left the value alone (see ZC_SR_OK_DECL).
60
- */
61
- export function superRefineFastTest(check, expr, g) {
62
- emitSuperRefineRunner(g.ctx);
63
- const ok = emitRuntimeHelper(g.ctx, "__zcSrOk", ZC_SR_OK_DECL);
64
- return `${ok}(${emitEffectCallable(g.ctx, check)},${expr})`;
46
+ * Fast-path test for a SuperRefineEffectCheckIR: a boolean term reporting that
47
+ * the callback added no issue and left the value alone (see ZC_SR_OK_DECL).
48
+ */
49
+ function superRefineFastTest(check, expr, g) {
50
+ emitSuperRefineRunner(g.ctx);
51
+ return `${emitRuntimeHelper(g.ctx, "__zcSrOk", ZC_SR_OK_DECL)}(${emitEffectCallable(g.ctx, check)},${expr})`;
65
52
  }
66
53
  /**
67
- * Generate code for a SuperRefineEffectCheckIR: call the payload-taking
68
- * callback with a synthesized `{ value, issues }` and merge what it collected.
69
- * zod's own wrapper installs `addIssue` and normalizes the result, so the
70
- * issues are zod's — the helper only reprojects them onto this node's path and
71
- * strips the internal bookkeeping zod deletes before they become visible.
72
- *
73
- * The payload's `value` is writable public API, so it is written back to the
74
- * output slot the way an overwrite effect is. This walk is always the eager one
75
- * (the node reports as mutating, see hasMutation), so the write-back lands on
76
- * every parse that reaches it — not only on failures.
77
- */
78
- export function superRefineCheck(check, expr, g) {
79
- emitSuperRefineRunner(g.ctx);
80
- const helper = emitRuntimeHelper(g.ctx, "__zcSr", ZC_SR_DECL);
81
- const fn = emitEffectCallable(g.ctx, check);
82
- const p = g.temp("sp");
83
- let code = `var ${p}=${helper}(${fn},${expr},${g.path},${g.issues});${g.output}=${p}.value;`;
84
- // Inside a union option, an aborting issue must mark the option aborted so
85
- // pruning matches zod (see ZC_SR_DECL); elsewhere the flag is unobserved.
86
- if (g.aborted)
87
- code += `if(${p}.aborted){${g.aborted}=true;}`;
88
- return code;
54
+ * Generate code for a SuperRefineEffectCheckIR: call the payload-taking
55
+ * callback with a synthesized `{ value, issues }` and merge what it collected.
56
+ * zod's own wrapper installs `addIssue` and normalizes the result, so the
57
+ * issues are zod's — the helper only reprojects them onto this node's path and
58
+ * strips the internal bookkeeping zod deletes before they become visible.
59
+ *
60
+ * The payload's `value` is writable public API, so it is written back to the
61
+ * output slot the way an overwrite effect is. This walk is always the eager one
62
+ * (the node reports as mutating, see hasMutation), so the write-back lands on
63
+ * every parse that reaches it — not only on failures.
64
+ */
65
+ function superRefineCheck(check, expr, g) {
66
+ emitSuperRefineRunner(g.ctx);
67
+ const helper = emitRuntimeHelper(g.ctx, "__zcSr", ZC_SR_DECL);
68
+ const fn = emitEffectCallable(g.ctx, check);
69
+ const p = g.temp("sp");
70
+ let code = `var ${p}=${helper}(${fn},${expr},${g.path},${g.issues});${g.output}=${p}.value;`;
71
+ if (g.aborted) code += `if(${p}.aborted){${g.aborted}=true;}`;
72
+ return code;
89
73
  }
74
+ //#endregion
75
+ export { refineCheck, slowEffect, superRefineCheck, superRefineFastTest };
76
+
90
77
  //# sourceMappingURL=effect.js.map