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 +1 @@
1
- {"version":3,"file":"static-filter.js","sourceRoot":"","sources":["../src/static-filter.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AASzC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAuB9B,4EAA4E;AAC5E,IAAI,kBAA6C,CAAC;AAElD,SAAS,cAAc;IACrB,kBAAkB,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAC5D,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,OAA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CAAC"}
1
+ {"version":3,"file":"static-filter.js","names":[],"sources":["../src/static-filter.ts"],"sourcesContent":["import path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type {\n AnyNode,\n AssignmentExpression,\n Expression,\n Program,\n Statement,\n VariableDeclaration,\n} from \"acorn\";\nimport { parse } from \"acorn\";\nimport type { Jiti } from \"jiti\";\n\n/**\n * Static pre-filter: decide whether a source file could export Zod schemas\n * WITHOUT executing it.\n *\n * Discovery executes candidate files (and, transitively, their whole import\n * graph) to scan exports. In autoDiscover mode most files that import zod\n * only export functions, components, or constants — executing them is pure\n * waste. This filter transpiles the single file (no dependencies) with\n * jiti's transform and inspects the top-level exports of the resulting\n * CommonJS with acorn.\n *\n * Conservative by construction: it returns false (\"skip\") only when every\n * export is statically provable as a non-schema (function, class, arrow,\n * literal, ...). Anything unrecognized — call expressions, re-exports,\n * `export *`, dynamic patterns, transpile/parse failures — keeps the file a\n * candidate, so a filter miss costs one execution, never a schema.\n */\n\ntype Classification = \"safe\" | \"candidate\";\n\n/** Lazily created jiti instance used only for single-file transpilation. */\nlet transformerPromise: Promise<Jiti> | undefined;\n\nfunction getTransformer(): Promise<Jiti> {\n transformerPromise ??= import(\"jiti\").then(({ createJiti }) =>\n createJiti(pathToFileURL(path.resolve(\"__zod-compiler-static-filter__.mjs\")).href),\n );\n return transformerPromise;\n}\n\n/**\n * Check whether a file's exports could include Zod schemas (or compile()\n * results) without executing the file. `filename` selects the TS/JSX\n * transforms; the file does not need to exist on disk.\n */\nexport async function mayExportSchemas(code: string, filename: string): Promise<boolean> {\n let transpiled: string;\n try {\n const jiti = await getTransformer();\n transpiled = jiti.transform({\n source: code,\n filename,\n ts: /\\.[cm]?tsx?$/.test(filename),\n jsx: /\\.[cm]?[jt]sx$/.test(filename),\n // async mode keeps top-level await and emits `await jitiImport(...)`\n // instead of failing — statements stay top-level either way.\n async: true,\n });\n } catch {\n return true;\n }\n // jiti reports parse failures by embedding an error marker in the output\n // instead of throwing. We can't analyze such files — keep them candidates\n // so the real loader surfaces (or tolerates) the failure exactly as before.\n if (transpiled.includes(\"__JITI_ERROR__\")) return true;\n\n let program: Program;\n try {\n // Module mode: the CJS output has no import/export statements, but may\n // contain top-level await (async transform).\n program = parse(transpiled, { ecmaVersion: \"latest\", sourceType: \"module\" });\n } catch {\n return true;\n }\n\n return analyzeProgram(program);\n}\n\n/** Where an assignment target sends its value, in discovery terms. */\ntype ExportTarget =\n | { kind: \"named\"; name: string }\n | { kind: \"default\" }\n | { kind: \"local\"; name: string }\n | { kind: \"ignored\" }\n | { kind: \"unknown\" };\n\nfunction analyzeProgram(program: Program): boolean {\n // Pass 1: top-level bindings for identifier resolution, plus the set of\n // identifier nodes that are \"expected\" (declaration ids and exports-chain\n // participants). Pass 2 counts every OTHER reference: a name referenced\n // outside its declaration/export may be mutated after creation\n // (defineProperty, member writes, helper calls), so object/array values\n // it names cannot be proven schema-free.\n const safeDecls = new Set<string>();\n const varInits = new Map<string, Expression | null>();\n const expectedNodes = new Set<object>();\n\n function recordChainNodes(expr: Expression): void {\n let node = expr;\n let hasExportTarget = false;\n while (node.type === \"AssignmentExpression\" && node.operator === \"=\") {\n if (node.left.type === \"Identifier\") {\n // Assignment LHS identifiers rebind — they never read the value.\n expectedNodes.add(node.left);\n } else if (node.left.type === \"MemberExpression\" && mentionsExports(node.left)) {\n hasExportTarget = true;\n }\n node = node.right;\n }\n // The bare-identifier value of an export chain (`exports.f = f`) is the\n // export itself; in a plain local chain (`alias = obj`) it is a real\n // aliasing reference and must count toward taint.\n if (hasExportTarget && node.type === \"Identifier\") expectedNodes.add(node);\n }\n\n for (const stmt of program.body) {\n if (stmt.type === \"FunctionDeclaration\" || stmt.type === \"ClassDeclaration\") {\n safeDecls.add(stmt.id.name);\n expectedNodes.add(stmt.id);\n } else if (stmt.type === \"VariableDeclaration\") {\n for (const decl of stmt.declarations) {\n if (decl.id.type === \"Identifier\") {\n expectedNodes.add(decl.id);\n // The init may be an `exports.X = value` chain — resolution should\n // see the final value expression.\n varInits.set(decl.id.name, decl.init ? unwrapAssignmentChain(decl.init).value : null);\n }\n if (decl.init) recordChainNodes(decl.init);\n }\n } else if (stmt.type === \"ExpressionStatement\") {\n recordChainNodes(stmt.expression);\n }\n }\n\n const referencedNames = collectReferencedNames(program, expectedNodes);\n\n function resolveIdentifier(name: string, defaultish: boolean, seen: Set<string>): Classification {\n if (seen.has(name)) return \"candidate\";\n seen.add(name);\n if (safeDecls.has(name)) return \"safe\";\n const init = varInits.get(name);\n if (init === undefined || init === null) return \"candidate\";\n return classifyValue(init, defaultish, seen, [name]);\n }\n\n /**\n * Could this expression evaluate to a Zod schema (an object carrying\n * `_zod.def` or the compile() marker)? `bindingNames` are the local\n * aliases of the value — a mutable container (object/array) is only safe\n * when none of its aliases are referenced elsewhere in the file.\n */\n function classifyValue(\n node: Expression,\n defaultish: boolean,\n seen: Set<string>,\n bindingNames: readonly string[],\n ): Classification {\n switch (node.type) {\n case \"Literal\":\n case \"TemplateLiteral\":\n case \"ArrowFunctionExpression\":\n case \"FunctionExpression\":\n case \"ClassExpression\":\n case \"UnaryExpression\":\n case \"UpdateExpression\":\n case \"BinaryExpression\":\n return \"safe\";\n case \"ObjectExpression\":\n case \"ArrayExpression\":\n // Discovery unwraps the properties of a default export object (and\n // arrays are objects), so containers are candidates there. Named\n // export containers are never unwrapped — but a container whose\n // alias is referenced elsewhere may be mutated into a schema shape.\n if (defaultish) return \"candidate\";\n return bindingNames.some((n) => referencedNames.has(n)) ? \"candidate\" : \"safe\";\n case \"Identifier\":\n return resolveIdentifier(node.name, defaultish, seen);\n case \"ConditionalExpression\":\n return classifyValue(node.consequent, defaultish, seen, bindingNames) === \"safe\" &&\n classifyValue(node.alternate, defaultish, seen, bindingNames) === \"safe\"\n ? \"safe\"\n : \"candidate\";\n case \"LogicalExpression\":\n return classifyValue(node.left, defaultish, seen, bindingNames) === \"safe\" &&\n classifyValue(node.right, defaultish, seen, bindingNames) === \"safe\"\n ? \"safe\"\n : \"candidate\";\n case \"SequenceExpression\": {\n const last = node.expressions[node.expressions.length - 1];\n return last ? classifyValue(last, defaultish, seen, bindingNames) : \"candidate\";\n }\n case \"AssignmentExpression\":\n return classifyValue(unwrapAssignmentChain(node).value, defaultish, seen, bindingNames);\n default:\n // CallExpression, NewExpression, MemberExpression, AwaitExpression, ...\n return \"candidate\";\n }\n }\n\n /** Process one assignment chain: classify the value for each export target. */\n function processAssignment(expr: Expression, declaredName?: string): Classification {\n const { targets, value } = unwrapAssignmentChain(expr);\n const bindingNames: string[] = declaredName ? [declaredName] : [];\n const exportTargets: ExportTarget[] = [];\n for (const target of targets) {\n const exportTarget = exportTargetOf(target);\n if (exportTarget.kind === \"unknown\") return \"candidate\";\n if (exportTarget.kind === \"local\") bindingNames.push(exportTarget.name);\n exportTargets.push(exportTarget);\n }\n for (const exportTarget of exportTargets) {\n if (exportTarget.kind === \"named\") {\n if (classifyValue(value, false, new Set(), bindingNames) === \"candidate\")\n return \"candidate\";\n } else if (exportTarget.kind === \"default\") {\n if (classifyValue(value, true, new Set(), bindingNames) === \"candidate\") return \"candidate\";\n }\n }\n // Catch-all: the value itself may reference exports in a shape we did\n // not positively classify (e.g. `exports.a = fn(exports.b)`).\n return mentionsExports(value) ? \"candidate\" : \"safe\";\n }\n\n function processVariableDeclaration(stmt: VariableDeclaration): Classification {\n for (const decl of stmt.declarations) {\n if (!decl.init) continue;\n if (decl.id.type === \"Identifier\") {\n if (processAssignment(decl.init, decl.id.name) === \"candidate\") return \"candidate\";\n } else if (mentionsExports(decl.init)) {\n // Destructuring declarators don't export by themselves (babel emits\n // separate `exports.x = x` statements), but be paranoid about any\n // exports reference hiding inside.\n return \"candidate\";\n }\n }\n return \"safe\";\n }\n\n function processStatement(stmt: Statement): Classification {\n switch (stmt.type) {\n case \"FunctionDeclaration\":\n case \"ClassDeclaration\":\n // Bodies that touch exports (hand-written CJS patterns) are opaque.\n return mentionsExports(stmt) ? \"candidate\" : \"safe\";\n case \"VariableDeclaration\":\n return processVariableDeclaration(stmt);\n case \"ExpressionStatement\":\n return processExpression(stmt.expression);\n case \"EmptyStatement\":\n return \"safe\";\n default:\n // if/try/for/... — babel never emits exports there for ESM input,\n // but hand-written CJS might (`if (x) module.exports = ...`).\n return mentionsExports(stmt) ? \"candidate\" : \"safe\";\n }\n }\n\n function processExpression(expr: Expression): Classification {\n switch (expr.type) {\n case \"Literal\":\n // Directive prologue (\"use strict\")\n return \"safe\";\n case \"AssignmentExpression\":\n return processAssignment(expr);\n case \"SequenceExpression\": {\n for (const sub of expr.expressions) {\n if (processExpression(sub) === \"candidate\") return \"candidate\";\n }\n return \"safe\";\n }\n case \"CallExpression\":\n if (isEsModuleMarker(expr)) return \"safe\";\n // Other exports-touching calls: re-export getters\n // (Object.defineProperty), `export *` loops, helpers.\n return mentionsExports(expr) ? \"candidate\" : \"safe\";\n default:\n return mentionsExports(expr) ? \"candidate\" : \"safe\";\n }\n }\n\n for (const stmt of program.body) {\n // The CJS output of jiti's transform contains no module declarations,\n // but if one ever appears, treat the file as a candidate.\n if (!isStatement(stmt)) return true;\n if (processStatement(stmt) === \"candidate\") return true;\n }\n return false;\n}\n\nfunction isStatement(node: AnyNode): node is Statement {\n return !node.type.startsWith(\"Import\") && !node.type.startsWith(\"Export\");\n}\n\n/**\n * Unwrap `a = b = c = value` into its assignment targets and final value.\n * Non-assignment expressions return zero targets and themselves as value.\n */\nfunction unwrapAssignmentChain(expr: Expression): {\n targets: AssignmentExpression[\"left\"][];\n value: Expression;\n} {\n const targets: AssignmentExpression[\"left\"][] = [];\n let value = expr;\n while (value.type === \"AssignmentExpression\" && value.operator === \"=\") {\n targets.push(value.left);\n value = value.right;\n }\n return { targets, value };\n}\n\n/** Classify an assignment target by what discovery would see. */\nfunction exportTargetOf(target: AssignmentExpression[\"left\"]): ExportTarget {\n if (target.type === \"Identifier\") {\n if (target.name === \"exports\" || target.name === \"module\") return { kind: \"unknown\" };\n return { kind: \"local\", name: target.name };\n }\n if (target.type !== \"MemberExpression\") {\n return mentionsExports(target) ? { kind: \"unknown\" } : { kind: \"ignored\" };\n }\n const propName =\n !target.computed && target.property.type === \"Identifier\"\n ? target.property.name\n : target.computed && target.property.type === \"Literal\"\n ? String(target.property.value)\n : null;\n\n // exports.X = ...\n if (target.object.type === \"Identifier\" && target.object.name === \"exports\") {\n if (propName === null) return { kind: \"unknown\" };\n return propName === \"default\" ? { kind: \"default\" } : { kind: \"named\", name: propName };\n }\n // module.exports = ... behaves like a default export after interop:\n // discovery unwraps its properties.\n if (target.object.type === \"Identifier\" && target.object.name === \"module\") {\n return propName === \"exports\" ? { kind: \"default\" } : { kind: \"unknown\" };\n }\n // module.exports.X = ...\n if (\n target.object.type === \"MemberExpression\" &&\n target.object.object.type === \"Identifier\" &&\n target.object.object.name === \"module\" &&\n !target.object.computed &&\n target.object.property.type === \"Identifier\" &&\n target.object.property.name === \"exports\"\n ) {\n if (propName === null) return { kind: \"unknown\" };\n return propName === \"default\" ? { kind: \"default\" } : { kind: \"named\", name: propName };\n }\n return mentionsExports(target) ? { kind: \"unknown\" } : { kind: \"ignored\" };\n}\n\n/** Object.defineProperty(exports, \"__esModule\", { value: true }) */\nfunction isEsModuleMarker(expr: Expression): boolean {\n return (\n expr.type === \"CallExpression\" &&\n expr.callee.type === \"MemberExpression\" &&\n expr.callee.object.type === \"Identifier\" &&\n expr.callee.object.name === \"Object\" &&\n !expr.callee.computed &&\n expr.callee.property.type === \"Identifier\" &&\n expr.callee.property.name === \"defineProperty\" &&\n expr.arguments[0]?.type === \"Identifier\" &&\n expr.arguments[0].name === \"exports\" &&\n expr.arguments[1]?.type === \"Literal\" &&\n expr.arguments[1].value === \"__esModule\"\n );\n}\n\n/**\n * Collect every identifier name used in a reference position, excluding the\n * `expected` nodes (declaration ids and exports-chain participants).\n * Non-reference positions — non-computed member properties, non-computed\n * object/class keys, labels — are skipped. Over-counting (e.g. shadowed\n * names in nested scopes, function params) only makes the filter more\n * conservative, never less safe.\n */\nfunction collectReferencedNames(program: Program, expected: Set<object>): Set<string> {\n const names = new Set<string>();\n const stack: unknown[] = [program];\n while (stack.length > 0) {\n const node = stack.pop();\n if (Array.isArray(node)) {\n for (const item of node) stack.push(item);\n continue;\n }\n if (typeof node !== \"object\" || node === null) continue;\n const record = node as Record<string, unknown>;\n const type = record[\"type\"];\n if (typeof type !== \"string\") continue;\n\n if (type === \"Identifier\") {\n if (!expected.has(node)) names.add(record[\"name\"] as string);\n continue;\n }\n\n for (const [key, value] of Object.entries(record)) {\n if (typeof value !== \"object\" || value === null) continue;\n // Skip non-reference identifier positions.\n if (key === \"property\" && type === \"MemberExpression\" && record[\"computed\"] !== true)\n continue;\n if (\n key === \"key\" &&\n (type === \"Property\" || type === \"PropertyDefinition\" || type === \"MethodDefinition\") &&\n record[\"computed\"] !== true\n )\n continue;\n if (key === \"label\") continue;\n stack.push(value);\n }\n }\n return names;\n}\n\n/** Deep-walk an acorn node for any reference to `exports` or `module`. */\nfunction mentionsExports(root: object): boolean {\n const stack: unknown[] = [root];\n while (stack.length > 0) {\n const node = stack.pop();\n if (Array.isArray(node)) {\n for (const item of node) stack.push(item);\n continue;\n }\n if (typeof node !== \"object\" || node === null) continue;\n const record = node as Record<string, unknown>;\n if (typeof record[\"type\"] === \"string\") {\n if (\n record[\"type\"] === \"Identifier\" &&\n (record[\"name\"] === \"exports\" || record[\"name\"] === \"module\")\n ) {\n return true;\n }\n }\n for (const value of Object.values(record)) {\n if (typeof value === \"object\" && value !== null) stack.push(value);\n }\n }\n return false;\n}\n"],"mappings":";;;;;AAkCA,IAAI;AAEJ,SAAS,iBAAgC;CACvC,uBAAuB,OAAO,OAAO,CAAC,MAAM,EAAE,iBAC5C,WAAW,cAAc,KAAK,QAAQ,oCAAoC,CAAC,CAAC,CAAC,IAAI,CACnF;CACA,OAAO;AACT;;;;;;AAOA,eAAsB,iBAAiB,MAAc,UAAoC;CACvF,IAAI;CACJ,IAAI;EAEF,cAAa,MADM,eAAe,EAAA,CAChB,UAAU;GAC1B,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PluginOptions } from "./unplugin/types.js";
2
+ //#region src/swc.d.ts
2
3
  /**
3
4
  * Minimal @swc/core option shape. zod-compiler keeps @swc/core optional so
4
5
  * non-SWC users do not install a native dependency just by using the package.
5
6
  * `inputSourceMap` matches @swc/core: a JSON string or a boolean — swc does
6
7
  * not accept map objects.
7
8
  */
8
- export interface SwcOptions {
9
- filename?: string | undefined;
10
- inputSourceMap?: boolean | string | undefined;
11
- sourceMaps?: boolean | "inline" | undefined;
12
- [key: string]: unknown;
9
+ interface SwcOptions {
10
+ filename?: string | undefined;
11
+ inputSourceMap?: boolean | string | undefined;
12
+ sourceMaps?: boolean | "inline" | undefined;
13
+ [key: string]: unknown;
13
14
  }
14
- export interface SwcOutput {
15
- code: string;
16
- map?: string | undefined;
17
- [key: string]: unknown;
15
+ interface SwcOutput {
16
+ code: string;
17
+ map?: string | undefined;
18
+ [key: string]: unknown;
18
19
  }
19
- export interface SwcCoreLike {
20
- transform(code: string, options?: SwcOptions): Promise<SwcOutput>;
20
+ interface SwcCoreLike {
21
+ transform(code: string, options?: SwcOptions): Promise<SwcOutput>;
21
22
  }
22
23
  /**
23
24
  * Plugin options that make sense for a transformer host. `apply` is Vite
@@ -26,35 +27,37 @@ export interface SwcCoreLike {
26
27
  * content themselves. `include`/`exclude` are honored: files they reject
27
28
  * pass through to SWC without the zod-compiler step.
28
29
  */
29
- export type ZodCompilerSwcOptions = Omit<ZodCompilerPluginOptions, "apply" | "cache" | "codegenMode"> & {
30
- /**
31
- * SWC is a transformer, not a bundler plugin host, so inline is the safe
32
- * default. Lean mode may emit virtual runtime imports that SWC cannot resolve
33
- * unless another tool handles them after SWC.
34
- */
35
- codegenMode?: "inline" | "lean" | undefined;
30
+ type ZodCompilerSwcOptions = Omit<ZodCompilerPluginOptions, "apply" | "cache" | "codegenMode"> & {
31
+ /**
32
+ * SWC is a transformer, not a bundler plugin host, so inline is the safe
33
+ * default. Lean mode may emit virtual runtime imports that SWC cannot resolve
34
+ * unless another tool handles them after SWC.
35
+ */
36
+ codegenMode?: "inline" | "lean" | undefined;
36
37
  };
37
- export interface SwcBridgeDefaults {
38
- /** Options passed through to @swc/core.transform. */
39
- swc?: SwcOptions | undefined;
40
- /** zod-compiler options. Defaults match the build plugins except codegenMode is "inline". */
41
- zodCompiler?: ZodCompilerSwcOptions | undefined;
38
+ interface SwcBridgeDefaults {
39
+ /** Options passed through to @swc/core.transform. */
40
+ swc?: SwcOptions | undefined;
41
+ /** zod-compiler options. Defaults match the build plugins except codegenMode is "inline". */
42
+ zodCompiler?: ZodCompilerSwcOptions | undefined;
42
43
  }
43
- export interface SwcBridgeTransformOptions extends SwcBridgeDefaults {
44
- /** Absolute or project-relative filename for schema discovery and SWC config resolution. */
45
- filename: string;
44
+ interface SwcBridgeTransformOptions extends SwcBridgeDefaults {
45
+ /** Absolute or project-relative filename for schema discovery and SWC config resolution. */
46
+ filename: string;
46
47
  }
47
- export interface SwcBridge {
48
- transform(code: string, options: SwcBridgeTransformOptions): Promise<SwcOutput>;
49
- transformFile(filename: string, options?: SwcBridgeDefaults): Promise<SwcOutput>;
48
+ interface SwcBridge {
49
+ transform(code: string, options: SwcBridgeTransformOptions): Promise<SwcOutput>;
50
+ transformFile(filename: string, options?: SwcBridgeDefaults): Promise<SwcOutput>;
50
51
  }
51
- export declare function transform(code: string, options: SwcBridgeTransformOptions): Promise<SwcOutput>;
52
- export declare function transformFile(filename: string, options?: SwcBridgeDefaults): Promise<SwcOutput>;
53
- export declare function createSwcCompiler(defaults?: SwcBridgeDefaults): SwcBridge;
52
+ declare function transform(code: string, options: SwcBridgeTransformOptions): Promise<SwcOutput>;
53
+ declare function transformFile(filename: string, options?: SwcBridgeDefaults): Promise<SwcOutput>;
54
+ declare function createSwcCompiler(defaults?: SwcBridgeDefaults): SwcBridge;
54
55
  /**
55
56
  * Test seam for the SWC bridge. It is exported because it is also useful for
56
57
  * custom hosts that already own a @swc/core-compatible transform function.
57
58
  */
58
- export declare function transformWithSwc(swc: SwcCoreLike, code: string, options: SwcBridgeTransformOptions): Promise<SwcOutput>;
59
- export default function zodCompiler(defaults?: SwcBridgeDefaults): SwcBridge;
59
+ declare function transformWithSwc(swc: SwcCoreLike, code: string, options: SwcBridgeTransformOptions): Promise<SwcOutput>;
60
+ declare function zodCompiler(defaults?: SwcBridgeDefaults): SwcBridge;
61
+ //#endregion
62
+ export { SwcBridge, SwcBridgeDefaults, SwcBridgeTransformOptions, SwcCoreLike, SwcOptions, SwcOutput, ZodCompilerSwcOptions, createSwcCompiler, zodCompiler as default, transform, transformFile, transformWithSwc };
60
63
  //# sourceMappingURL=swc.d.ts.map
package/dist/swc.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"swc.d.ts","sourceRoot":"","sources":["../src/swc.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAoB,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAEtF;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;IAC9C,UAAU,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC5C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CACnE;AAED;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,GAAG,IAAI,CACtC,wBAAwB,EACxB,OAAO,GAAG,OAAO,GAAG,aAAa,CAClC,GAAG;IACF;;;;OAIG;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cAAc,UAAU,aAAa,QAAQ;;;;;;;;;KAU7C,wBAAwB,KAClC;;;;;;EAQA;;UAGe;;EAEf,MAAM;;EAEN,cAAc;;UAGC,kCAAkC;;EAEjD;;UAGe;EACf,UAAU,cAAc,SAAS,4BAA4B,QAAQ;EACrE,cAAc,kBAAkB,UAAU,oBAAoB,QAAQ;;iBAoFlD,UACpB,cACA,SAAS,4BACR,QAAQ;iBAIW,cACpB,kBACA,UAAU,oBACT,QAAQ;iBAKK,kBAAkB,WAAW,oBAAoB;;;;;iBAgB3C,iBACpB,KAAK,aACL,cACA,SAAS,4BACR,QAAQ;iBAIa,YAAY,WAAW,oBAAoB"}
package/dist/swc.js CHANGED
@@ -1,97 +1,104 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
1
  import { invalidateModuleCache } from "./loader.js";
4
2
  import { shouldTransform, transformCodeWithMap } from "./unplugin/transform.js";
3
+ import path from "node:path";
4
+ import fs from "node:fs/promises";
5
+ //#region src/swc.ts
5
6
  function toTransformOptions(options) {
6
- const output = options?.output ?? "schema";
7
- return {
8
- mode: options?.codegenMode ?? "inline",
9
- verbose: options?.verbose,
10
- zodCompat: output === "schema" || output === "compact",
11
- compact: output === "compact",
12
- autoDiscover: (options?.schemas ?? "auto") === "auto",
13
- hoist: options?.hoist,
14
- };
7
+ const output = options?.output ?? "schema";
8
+ return {
9
+ mode: options?.codegenMode ?? "inline",
10
+ verbose: options?.verbose,
11
+ zodCompat: output === "schema" || output === "compact",
12
+ compact: output === "compact",
13
+ autoDiscover: (options?.schemas ?? "auto") === "auto",
14
+ hoist: options?.hoist
15
+ };
15
16
  }
16
17
  /**
17
- * Per-call options win key-by-key over factory defaults. The merge is
18
- * shallow: a per-call `swc.jsc` replaces the default `jsc` wholesale rather
19
- * than deep-merging parser/target settings.
20
- */
18
+ * Per-call options win key-by-key over factory defaults. The merge is
19
+ * shallow: a per-call `swc.jsc` replaces the default `jsc` wholesale rather
20
+ * than deep-merging parser/target settings.
21
+ */
21
22
  function mergeOptions(defaults, options) {
22
- return {
23
- filename: options.filename,
24
- swc: { ...defaults?.swc, ...options.swc },
25
- zodCompiler: { ...defaults?.zodCompiler, ...options.zodCompiler },
26
- };
23
+ return {
24
+ filename: options.filename,
25
+ swc: {
26
+ ...defaults?.swc,
27
+ ...options.swc
28
+ },
29
+ zodCompiler: {
30
+ ...defaults?.zodCompiler,
31
+ ...options.zodCompiler
32
+ }
33
+ };
27
34
  }
28
35
  async function loadSwc() {
29
- try {
30
- return (await import("@swc/core"));
31
- }
32
- catch (error) {
33
- const cause = error instanceof Error ? `: ${error.message}` : "";
34
- throw new Error(`zod-compiler/swc requires @swc/core to be installed by the consuming project${cause}`);
35
- }
36
+ try {
37
+ return await import("@swc/core");
38
+ } catch (error) {
39
+ const cause = error instanceof Error ? `: ${error.message}` : "";
40
+ throw new Error(`zod-compiler/swc requires @swc/core to be installed by the consuming project${cause}`);
41
+ }
36
42
  }
37
43
  /**
38
- * Last content seen per filename. Discovery executes schema files from DISK
39
- * through a module cache that outlives transform calls, so when a host (dev
40
- * server, watch-mode test runner) re-transforms a file with new content, the
41
- * stale executions must be dropped or the compiled validators keep
42
- * reflecting the old schema. Same content-diff scheme as the unplugin
43
- * transform hook; tracked for every file fed to the bridge — an excluded
44
- * file can still be a dependency a schema file executed.
45
- */
46
- const lastSeenCode = new Map();
44
+ * Last content seen per filename. Discovery executes schema files from DISK
45
+ * through a module cache that outlives transform calls, so when a host (dev
46
+ * server, watch-mode test runner) re-transforms a file with new content, the
47
+ * stale executions must be dropped or the compiled validators keep
48
+ * reflecting the old schema. Same content-diff scheme as the unplugin
49
+ * transform hook; tracked for every file fed to the bridge — an excluded
50
+ * file can still be a dependency a schema file executed.
51
+ */
52
+ const lastSeenCode = /* @__PURE__ */ new Map();
47
53
  function invalidateOnContentChange(filename, code) {
48
- const key = path.resolve(filename);
49
- const previous = lastSeenCode.get(key);
50
- if (previous !== undefined && previous !== code) {
51
- invalidateModuleCache();
52
- }
53
- lastSeenCode.set(key, code);
54
+ const key = path.resolve(filename);
55
+ const previous = lastSeenCode.get(key);
56
+ if (previous !== void 0 && previous !== code) invalidateModuleCache();
57
+ lastSeenCode.set(key, code);
54
58
  }
55
59
  async function transformWith(swc, code, options) {
56
- invalidateOnContentChange(options.filename, code);
57
- const zodResult = shouldTransform(options.filename, options.zodCompiler)
58
- ? await transformCodeWithMap(code, options.filename, toTransformOptions(options.zodCompiler))
59
- : null;
60
- const swcOptions = {
61
- ...options.swc,
62
- filename: options.swc?.filename ?? options.filename,
63
- };
64
- if (zodResult?.map && swcOptions.inputSourceMap === undefined) {
65
- swcOptions.inputSourceMap = JSON.stringify(zodResult.map);
66
- }
67
- return swc.transform(zodResult?.code ?? code, swcOptions);
60
+ invalidateOnContentChange(options.filename, code);
61
+ const zodResult = shouldTransform(options.filename, options.zodCompiler) ? await transformCodeWithMap(code, options.filename, toTransformOptions(options.zodCompiler)) : null;
62
+ const swcOptions = {
63
+ ...options.swc,
64
+ filename: options.swc?.filename ?? options.filename
65
+ };
66
+ if (zodResult?.map && swcOptions.inputSourceMap === void 0) swcOptions.inputSourceMap = JSON.stringify(zodResult.map);
67
+ return swc.transform(zodResult?.code ?? code, swcOptions);
68
68
  }
69
- export async function transform(code, options) {
70
- return transformWith(await loadSwc(), code, options);
69
+ async function transform(code, options) {
70
+ return transformWith(await loadSwc(), code, options);
71
71
  }
72
- export async function transformFile(filename, options) {
73
- const code = await fs.readFile(filename, "utf8");
74
- return transform(code, { ...options, filename });
72
+ async function transformFile(filename, options) {
73
+ return transform(await fs.readFile(filename, "utf8"), {
74
+ ...options,
75
+ filename
76
+ });
75
77
  }
76
- export function createSwcCompiler(defaults) {
77
- return {
78
- transform(code, options) {
79
- return transform(code, mergeOptions(defaults, options));
80
- },
81
- async transformFile(filename, options) {
82
- const code = await fs.readFile(filename, "utf8");
83
- return transform(code, mergeOptions(defaults, { ...options, filename }));
84
- },
85
- };
78
+ function createSwcCompiler(defaults) {
79
+ return {
80
+ transform(code, options) {
81
+ return transform(code, mergeOptions(defaults, options));
82
+ },
83
+ async transformFile(filename, options) {
84
+ return transform(await fs.readFile(filename, "utf8"), mergeOptions(defaults, {
85
+ ...options,
86
+ filename
87
+ }));
88
+ }
89
+ };
86
90
  }
87
91
  /**
88
- * Test seam for the SWC bridge. It is exported because it is also useful for
89
- * custom hosts that already own a @swc/core-compatible transform function.
90
- */
91
- export async function transformWithSwc(swc, code, options) {
92
- return transformWith(swc, code, options);
92
+ * Test seam for the SWC bridge. It is exported because it is also useful for
93
+ * custom hosts that already own a @swc/core-compatible transform function.
94
+ */
95
+ async function transformWithSwc(swc, code, options) {
96
+ return transformWith(swc, code, options);
93
97
  }
94
- export default function zodCompiler(defaults) {
95
- return createSwcCompiler(defaults);
98
+ function zodCompiler(defaults) {
99
+ return createSwcCompiler(defaults);
96
100
  }
101
+ //#endregion
102
+ export { createSwcCompiler, zodCompiler as default, transform, transformFile, transformWithSwc };
103
+
97
104
  //# sourceMappingURL=swc.js.map
package/dist/swc.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"swc.js","sourceRoot":"","sources":["../src/swc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AA8DhF,SAAS,kBAAkB,CAAC,OAA+B;IACzD,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,QAAQ,CAAC;IAC3C,OAAO;QACL,IAAI,EAAE,OAAO,EAAE,WAAW,IAAI,QAAQ;QACtC,OAAO,EAAE,OAAO,EAAE,OAAO;QACzB,SAAS,EAAE,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,SAAS;QACtD,OAAO,EAAE,MAAM,KAAK,SAAS;QAC7B,YAAY,EAAE,CAAC,OAAO,EAA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,CAAC,IAAI,EAAE,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;QAC1D,CAAC;QACD,KAAK,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO;YACnC,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YACjD,OAAO,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,QAAQ,EAAE,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;QAC3E,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,GAAgB,EAChB,IAAY,EACZ,OAAkC;IAElC,OAAO,aAAa,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,QAA4B;IAC9D,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC"}
1
+ {"version":3,"file":"swc.js","names":[],"sources":["../src/swc.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { invalidateModuleCache } from \"./loader.js\";\nimport { shouldTransform, transformCodeWithMap } from \"./unplugin/transform.js\";\nimport type { TransformOptions, ZodCompilerPluginOptions } from \"./unplugin/types.js\";\n\n/**\n * Minimal @swc/core option shape. zod-compiler keeps @swc/core optional so\n * non-SWC users do not install a native dependency just by using the package.\n * `inputSourceMap` matches @swc/core: a JSON string or a boolean — swc does\n * not accept map objects.\n */\nexport interface SwcOptions {\n filename?: string | undefined;\n inputSourceMap?: boolean | string | undefined;\n sourceMaps?: boolean | \"inline\" | undefined;\n [key: string]: unknown;\n}\n\nexport interface SwcOutput {\n code: string;\n map?: string | undefined;\n [key: string]: unknown;\n}\n\nexport interface SwcCoreLike {\n transform(code: string, options?: SwcOptions): Promise<SwcOutput>;\n}\n\n/**\n * Plugin options that make sense for a transformer host. `apply` is Vite\n * lifecycle and `cache` is the bundler disk cache — the bridge keeps no\n * persistent cache, so hosts that need one must key transform results on\n * content themselves. `include`/`exclude` are honored: files they reject\n * pass through to SWC without the zod-compiler step.\n */\nexport type ZodCompilerSwcOptions = Omit<\n ZodCompilerPluginOptions,\n \"apply\" | \"cache\" | \"codegenMode\"\n> & {\n /**\n * SWC is a transformer, not a bundler plugin host, so inline is the safe\n * default. Lean mode may emit virtual runtime imports that SWC cannot resolve\n * unless another tool handles them after SWC.\n */\n codegenMode?: \"inline\" | \"lean\" | undefined;\n};\n\nexport interface SwcBridgeDefaults {\n /** Options passed through to @swc/core.transform. */\n swc?: SwcOptions | undefined;\n /** zod-compiler options. Defaults match the build plugins except codegenMode is \"inline\". */\n zodCompiler?: ZodCompilerSwcOptions | undefined;\n}\n\nexport interface SwcBridgeTransformOptions extends SwcBridgeDefaults {\n /** Absolute or project-relative filename for schema discovery and SWC config resolution. */\n filename: string;\n}\n\nexport interface SwcBridge {\n transform(code: string, options: SwcBridgeTransformOptions): Promise<SwcOutput>;\n transformFile(filename: string, options?: SwcBridgeDefaults): Promise<SwcOutput>;\n}\n\nfunction toTransformOptions(options?: ZodCompilerSwcOptions): TransformOptions {\n const output = options?.output ?? \"schema\";\n return {\n mode: options?.codegenMode ?? \"inline\",\n verbose: options?.verbose,\n zodCompat: output === \"schema\" || output === \"compact\",\n compact: output === \"compact\",\n autoDiscover: (options?.schemas ?? \"auto\") === \"auto\",\n hoist: options?.hoist,\n };\n}\n\n/**\n * Per-call options win key-by-key over factory defaults. The merge is\n * shallow: a per-call `swc.jsc` replaces the default `jsc` wholesale rather\n * than deep-merging parser/target settings.\n */\nfunction mergeOptions(\n defaults: SwcBridgeDefaults | undefined,\n options: SwcBridgeTransformOptions,\n): SwcBridgeTransformOptions {\n return {\n filename: options.filename,\n swc: { ...defaults?.swc, ...options.swc },\n zodCompiler: { ...defaults?.zodCompiler, ...options.zodCompiler },\n };\n}\n\nasync function loadSwc(): Promise<SwcCoreLike> {\n try {\n return (await import(\"@swc/core\")) as unknown as SwcCoreLike;\n } catch (error) {\n const cause = error instanceof Error ? `: ${error.message}` : \"\";\n throw new Error(\n `zod-compiler/swc requires @swc/core to be installed by the consuming project${cause}`,\n );\n }\n}\n\n/**\n * Last content seen per filename. Discovery executes schema files from DISK\n * through a module cache that outlives transform calls, so when a host (dev\n * server, watch-mode test runner) re-transforms a file with new content, the\n * stale executions must be dropped or the compiled validators keep\n * reflecting the old schema. Same content-diff scheme as the unplugin\n * transform hook; tracked for every file fed to the bridge — an excluded\n * file can still be a dependency a schema file executed.\n */\nconst lastSeenCode = new Map<string, string>();\n\nfunction invalidateOnContentChange(filename: string, code: string): void {\n const key = path.resolve(filename);\n const previous = lastSeenCode.get(key);\n if (previous !== undefined && previous !== code) {\n invalidateModuleCache();\n }\n lastSeenCode.set(key, code);\n}\n\nasync function transformWith(\n swc: SwcCoreLike,\n code: string,\n options: SwcBridgeTransformOptions,\n): Promise<SwcOutput> {\n invalidateOnContentChange(options.filename, code);\n\n const zodResult = shouldTransform(options.filename, options.zodCompiler)\n ? await transformCodeWithMap(code, options.filename, toTransformOptions(options.zodCompiler))\n : null;\n\n const swcOptions: SwcOptions = {\n ...options.swc,\n filename: options.swc?.filename ?? options.filename,\n };\n if (zodResult?.map && swcOptions.inputSourceMap === undefined) {\n swcOptions.inputSourceMap = JSON.stringify(zodResult.map);\n }\n\n return swc.transform(zodResult?.code ?? code, swcOptions);\n}\n\nexport async function transform(\n code: string,\n options: SwcBridgeTransformOptions,\n): Promise<SwcOutput> {\n return transformWith(await loadSwc(), code, options);\n}\n\nexport async function transformFile(\n filename: string,\n options?: SwcBridgeDefaults,\n): Promise<SwcOutput> {\n const code = await fs.readFile(filename, \"utf8\");\n return transform(code, { ...options, filename });\n}\n\nexport function createSwcCompiler(defaults?: SwcBridgeDefaults): SwcBridge {\n return {\n transform(code, options) {\n return transform(code, mergeOptions(defaults, options));\n },\n async transformFile(filename, options) {\n const code = await fs.readFile(filename, \"utf8\");\n return transform(code, mergeOptions(defaults, { ...options, filename }));\n },\n };\n}\n\n/**\n * Test seam for the SWC bridge. It is exported because it is also useful for\n * custom hosts that already own a @swc/core-compatible transform function.\n */\nexport async function transformWithSwc(\n swc: SwcCoreLike,\n code: string,\n options: SwcBridgeTransformOptions,\n): Promise<SwcOutput> {\n return transformWith(swc, code, options);\n}\n\nexport default function zodCompiler(defaults?: SwcBridgeDefaults): SwcBridge {\n return createSwcCompiler(defaults);\n}\n"],"mappings":";;;;;AAiEA,SAAS,mBAAmB,SAAmD;CAC7E,MAAM,SAAS,SAAS,UAAU;CAClC,OAAO;EACL,MAAM,SAAS,eAAe;EAC9B,SAAS,SAAS;EAClB,WAAW,WAAW,YAAY,WAAW;EAC7C,SAAS,WAAW;EACpB,eAAe,SAAS,WAAW,YAAY;EAC/C,OAAO,SAAS;CAClB;AACF;;;;;;AAOA,SAAS,aACP,UACA,SAC2B;CAC3B,OAAO;EACL,UAAU,QAAQ;EAClB,KAAK;GAAE,GAAG,UAAU;GAAK,GAAG,QAAQ;EAAI;EACxC,aAAa;GAAE,GAAG,UAAU;GAAa,GAAG,QAAQ;EAAY;CAClE;AACF;AAEA,eAAe,UAAgC;CAC7C,IAAI;EACF,OAAQ,MAAM,OAAO;CACvB,SAAS,OAAO;EACd,MAAM,QAAQ,iBAAiB,QAAQ,KAAK,MAAM,YAAY;EAC9D,MAAM,IAAI,MACR,+EAA+E,OACjF;CACF;AACF;;;;;;;;;;AAWA,MAAM,+BAAe,IAAI,IAAoB;AAE7C,SAAS,0BAA0B,UAAkB,MAAoB;CACvE,MAAM,MAAM,KAAK,QAAQ,QAAQ;CACjC,MAAM,WAAW,aAAa,IAAI,GAAG;CACrC,IAAI,aAAa,KAAA,KAAa,aAAa,MACzC,sBAAsB;CAExB,aAAa,IAAI,KAAK,IAAI;AAC5B;AAEA,eAAe,cACb,KACA,MACA,SACoB;CACpB,0BAA0B,QAAQ,UAAU,IAAI;CAEhD,MAAM,YAAY,gBAAgB,QAAQ,UAAU,QAAQ,WAAW,IACnE,MAAM,qBAAqB,MAAM,QAAQ,UAAU,mBAAmB,QAAQ,WAAW,CAAC,IAC1F;CAEJ,MAAM,aAAyB;EAC7B,GAAG,QAAQ;EACX,UAAU,QAAQ,KAAK,YAAY,QAAQ;CAC7C;CACA,IAAI,WAAW,OAAO,WAAW,mBAAmB,KAAA,GAClD,WAAW,iBAAiB,KAAK,UAAU,UAAU,GAAG;CAG1D,OAAO,IAAI,UAAU,WAAW,QAAQ,MAAM,UAAU;AAC1D;AAEA,eAAsB,UACpB,MACA,SACoB;CACpB,OAAO,cAAc,MAAM,QAAQ,GAAG,MAAM,OAAO;AACrD;AAEA,eAAsB,cACpB,UACA,SACoB;CAEpB,OAAO,UAAU,MADE,GAAG,SAAS,UAAU,MAAM,GACxB;EAAE,GAAG;EAAS;CAAS,CAAC;AACjD;AAEA,SAAgB,kBAAkB,UAAyC;CACzE,OAAO;EACL,UAAU,MAAM,SAAS;GACvB,OAAO,UAAU,MAAM,aAAa,UAAU,OAAO,CAAC;EACxD;EACA,MAAM,cAAc,UAAU,SAAS;GAErC,OAAO,UAAU,MADE,GAAG,SAAS,UAAU,MAAM,GACxB,aAAa,UAAU;IAAE,GAAG;IAAS;GAAS,CAAC,CAAC;EACzE;CACF;AACF;;;;;AAMA,eAAsB,iBACpB,KACA,MACA,SACoB;CACpB,OAAO,cAAc,KAAK,MAAM,OAAO;AACzC;AAEA,SAAwB,YAAY,UAAyC;CAC3E,OAAO,kBAAkB,QAAQ;AACnC"}
@@ -1,3 +1,6 @@
1
- declare const _default: (options?: import("./types.js").ZodCompilerPluginOptions | undefined) => Bun.BunPlugin;
2
- export default _default;
1
+ import { ZodCompilerPluginOptions } from "./types.js";
2
+ //#region src/unplugin/bun.d.ts
3
+ declare const _default: (options?: ZodCompilerPluginOptions | undefined) => Bun.BunPlugin;
4
+ //#endregion
5
+ export { _default as default };
3
6
  //# sourceMappingURL=bun.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bun.d.ts","sourceRoot":"","sources":["../../src/unplugin/bun.ts"],"names":[],"mappings":";AAEA,wBAA4B"}
1
+ {"version":3,"file":"bun.d.ts","names":[],"sources":["../../src/unplugin/bun.ts"],"mappings":""}
@@ -1,3 +1,7 @@
1
1
  import { unplugin } from "./index.js";
2
- export default unplugin.bun;
2
+ //#region src/unplugin/bun.ts
3
+ var bun_default = unplugin.bun;
4
+ //#endregion
5
+ export { bun_default as default };
6
+
3
7
  //# sourceMappingURL=bun.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bun.js","sourceRoot":"","sources":["../../src/unplugin/bun.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,eAAe,QAAQ,CAAC,GAAG,CAAC"}
1
+ {"version":3,"file":"bun.js","names":[],"sources":["../../src/unplugin/bun.ts"],"sourcesContent":["import { unplugin } from \"./index.js\";\n\nexport default unplugin.bun;\n"],"mappings":";;AAEA,IAAA,cAAe,SAAS"}
@@ -1,3 +1,4 @@
1
+ //#region src/unplugin/dep-graph.d.ts
1
2
  /**
2
3
  * Static per-file dependency graphs for disk-cache invalidation.
3
4
  *
@@ -36,17 +37,19 @@
36
37
  * crawl would be pure waste (and incomplete is the COMMON outcome on
37
38
  * large graphs — one dynamic import anywhere poisons the whole closure).
38
39
  */
39
- export interface StaticDeps {
40
- /** Absolute real paths of first-party files reachable from the entry. */
41
- deps: string[];
42
- /** False when the graph could not be fully analyzed — use the superset. */
43
- complete: boolean;
40
+ interface StaticDeps {
41
+ /** Absolute real paths of first-party files reachable from the entry. */
42
+ deps: string[];
43
+ /** False when the graph could not be fully analyzed — use the superset. */
44
+ complete: boolean;
44
45
  }
45
46
  /** Reset the per-process dep-graph memos (watch-mode file changes). */
46
- export declare function resetDepGraphMemo(): void;
47
+ declare function resetDepGraphMemo(): void;
47
48
  /**
48
49
  * Compute the static first-party dependency closure of `entryFile`.
49
50
  * The entry itself is excluded (its content is part of the cache key).
50
51
  */
51
- export declare function collectStaticDeps(entryFile: string): StaticDeps;
52
+ declare function collectStaticDeps(entryFile: string): StaticDeps;
53
+ //#endregion
54
+ export { StaticDeps, collectStaticDeps, resetDepGraphMemo };
52
55
  //# sourceMappingURL=dep-graph.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dep-graph.d.ts","sourceRoot":"","sources":["../../src/unplugin/dep-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAOH,MAAM,WAAW,UAAU;IACzB,yEAAyE;IACzE,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,2EAA2E;IAC3E,QAAQ,EAAE,OAAO,CAAC;CACnB;AAwCD,uEAAuE;AACvE,wBAAgB,iBAAiB,IAAI,IAAI,CAKxC;AA6LD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,CAwB/D"}
1
+ {"version":3,"file":"dep-graph.d.ts","names":[],"sources":["../../src/unplugin/dep-graph.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA4CiB;;EAEf;;EAEA;;;iBA0Cc;;;;;iBAsMA,kBAAkB,oBAAoB"}