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.
- package/README.md +9 -6
- package/dist/cli/commands/check.d.ts +10 -7
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +125 -148
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/generate.d.ts +22 -19
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +102 -133
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/commands/watch.d.ts +17 -15
- package/dist/cli/commands/watch.d.ts.map +1 -1
- package/dist/cli/commands/watch.js +126 -154
- package/dist/cli/commands/watch.js.map +1 -1
- package/dist/cli/emitter.d.ts +19 -16
- package/dist/cli/emitter.d.ts.map +1 -1
- package/dist/cli/emitter.js +55 -71
- package/dist/cli/emitter.js.map +1 -1
- package/dist/cli/errors.d.ts +4 -1
- package/dist/cli/errors.d.ts.map +1 -1
- package/dist/cli/errors.js +6 -2
- package/dist/cli/errors.js.map +1 -1
- package/dist/cli/index.d.ts +1 -3
- package/dist/cli/index.js +147 -160
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/logger.d.ts +18 -15
- package/dist/cli/logger.d.ts.map +1 -1
- package/dist/cli/logger.js +38 -37
- package/dist/cli/logger.js.map +1 -1
- package/dist/core/codegen/build-path.d.ts +7 -41
- package/dist/core/codegen/build-path.d.ts.map +1 -1
- package/dist/core/codegen/build-path.js +481 -570
- package/dist/core/codegen/build-path.js.map +1 -1
- package/dist/core/codegen/context.d.ts +256 -253
- package/dist/core/codegen/context.d.ts.map +1 -1
- package/dist/core/codegen/context.js +363 -437
- package/dist/core/codegen/context.js.map +1 -1
- package/dist/core/codegen/dedupe.d.ts +22 -56
- package/dist/core/codegen/dedupe.d.ts.map +1 -1
- package/dist/core/codegen/dedupe.js +150 -242
- package/dist/core/codegen/dedupe.js.map +1 -1
- package/dist/core/codegen/emit-issue.d.ts +44 -68
- package/dist/core/codegen/emit-issue.d.ts.map +1 -1
- package/dist/core/codegen/emit-issue.js +76 -108
- package/dist/core/codegen/emit-issue.js.map +1 -1
- package/dist/core/codegen/emit.d.ts +4 -1
- package/dist/core/codegen/emit.d.ts.map +1 -1
- package/dist/core/codegen/emit.js +16 -13
- package/dist/core/codegen/emit.js.map +1 -1
- package/dist/core/codegen/fast-path.d.ts +7 -12
- package/dist/core/codegen/fast-path.d.ts.map +1 -1
- package/dist/core/codegen/fast-path.js +116 -145
- package/dist/core/codegen/fast-path.js.map +1 -1
- package/dist/core/codegen/fast-size.d.ts +12 -26
- package/dist/core/codegen/fast-size.d.ts.map +1 -1
- package/dist/core/codegen/fast-size.js +169 -244
- package/dist/core/codegen/fast-size.js.map +1 -1
- package/dist/core/codegen/index.d.ts +25 -23
- package/dist/core/codegen/index.d.ts.map +1 -1
- package/dist/core/codegen/index.js +239 -405
- package/dist/core/codegen/index.js.map +1 -1
- package/dist/core/codegen/issue-decls.d.ts +15 -12
- package/dist/core/codegen/issue-decls.d.ts.map +1 -1
- package/dist/core/codegen/issue-decls.js +131 -162
- package/dist/core/codegen/issue-decls.js.map +1 -1
- package/dist/core/codegen/regex-unroll.d.ts +4 -1
- package/dist/core/codegen/regex-unroll.d.ts.map +1 -1
- package/dist/core/codegen/regex-unroll.js +173 -197
- package/dist/core/codegen/regex-unroll.js.map +1 -1
- package/dist/core/codegen/schemas/any.d.ts +7 -4
- package/dist/core/codegen/schemas/any.d.ts.map +1 -1
- package/dist/core/codegen/schemas/any.js +8 -4
- package/dist/core/codegen/schemas/any.js.map +1 -1
- package/dist/core/codegen/schemas/array.d.ts +8 -5
- package/dist/core/codegen/schemas/array.d.ts.map +1 -1
- package/dist/core/codegen/schemas/array.js +77 -95
- package/dist/core/codegen/schemas/array.js.map +1 -1
- package/dist/core/codegen/schemas/bigint.d.ts +7 -4
- package/dist/core/codegen/schemas/bigint.d.ts.map +1 -1
- package/dist/core/codegen/schemas/bigint.js +44 -56
- package/dist/core/codegen/schemas/bigint.js.map +1 -1
- package/dist/core/codegen/schemas/boolean.d.ts +7 -4
- package/dist/core/codegen/schemas/boolean.d.ts.map +1 -1
- package/dist/core/codegen/schemas/boolean.js +12 -11
- package/dist/core/codegen/schemas/boolean.js.map +1 -1
- package/dist/core/codegen/schemas/catch.d.ts +8 -5
- package/dist/core/codegen/schemas/catch.d.ts.map +1 -1
- package/dist/core/codegen/schemas/catch.js +23 -23
- package/dist/core/codegen/schemas/catch.js.map +1 -1
- package/dist/core/codegen/schemas/date.d.ts +7 -4
- package/dist/core/codegen/schemas/date.d.ts.map +1 -1
- package/dist/core/codegen/schemas/date.js +49 -68
- package/dist/core/codegen/schemas/date.js.map +1 -1
- package/dist/core/codegen/schemas/default.d.ts +9 -6
- package/dist/core/codegen/schemas/default.d.ts.map +1 -1
- package/dist/core/codegen/schemas/default.js +29 -27
- package/dist/core/codegen/schemas/default.js.map +1 -1
- package/dist/core/codegen/schemas/discriminated-union.d.ts +12 -10
- package/dist/core/codegen/schemas/discriminated-union.d.ts.map +1 -1
- package/dist/core/codegen/schemas/discriminated-union.js +153 -178
- package/dist/core/codegen/schemas/discriminated-union.js.map +1 -1
- package/dist/core/codegen/schemas/effect.d.ts +9 -6
- package/dist/core/codegen/schemas/effect.d.ts.map +1 -1
- package/dist/core/codegen/schemas/effect.js +54 -67
- package/dist/core/codegen/schemas/effect.js.map +1 -1
- package/dist/core/codegen/schemas/enum.d.ts +7 -4
- package/dist/core/codegen/schemas/enum.d.ts.map +1 -1
- package/dist/core/codegen/schemas/enum.js +15 -21
- package/dist/core/codegen/schemas/enum.js.map +1 -1
- package/dist/core/codegen/schemas/fallback.d.ts +6 -3
- package/dist/core/codegen/schemas/fallback.d.ts.map +1 -1
- package/dist/core/codegen/schemas/fallback.js +14 -13
- package/dist/core/codegen/schemas/fallback.js.map +1 -1
- package/dist/core/codegen/schemas/file.d.ts +7 -4
- package/dist/core/codegen/schemas/file.d.ts.map +1 -1
- package/dist/core/codegen/schemas/file.js +51 -57
- package/dist/core/codegen/schemas/file.js.map +1 -1
- package/dist/core/codegen/schemas/intersection.d.ts +8 -5
- package/dist/core/codegen/schemas/intersection.d.ts.map +1 -1
- package/dist/core/codegen/schemas/intersection.js +16 -13
- package/dist/core/codegen/schemas/intersection.js.map +1 -1
- package/dist/core/codegen/schemas/literal.d.ts +7 -4
- package/dist/core/codegen/schemas/literal.d.ts.map +1 -1
- package/dist/core/codegen/schemas/literal.js +20 -23
- package/dist/core/codegen/schemas/literal.js.map +1 -1
- package/dist/core/codegen/schemas/map.d.ts +8 -5
- package/dist/core/codegen/schemas/map.d.ts.map +1 -1
- package/dist/core/codegen/schemas/map.js +61 -67
- package/dist/core/codegen/schemas/map.js.map +1 -1
- package/dist/core/codegen/schemas/nan.d.ts +7 -4
- package/dist/core/codegen/schemas/nan.d.ts.map +1 -1
- package/dist/core/codegen/schemas/nan.js +8 -4
- package/dist/core/codegen/schemas/nan.js.map +1 -1
- package/dist/core/codegen/schemas/never.d.ts +7 -4
- package/dist/core/codegen/schemas/never.d.ts.map +1 -1
- package/dist/core/codegen/schemas/never.js +8 -4
- package/dist/core/codegen/schemas/never.js.map +1 -1
- package/dist/core/codegen/schemas/null.d.ts +7 -4
- package/dist/core/codegen/schemas/null.d.ts.map +1 -1
- package/dist/core/codegen/schemas/null.js +8 -4
- package/dist/core/codegen/schemas/null.js.map +1 -1
- package/dist/core/codegen/schemas/nullable.d.ts +8 -5
- package/dist/core/codegen/schemas/nullable.d.ts.map +1 -1
- package/dist/core/codegen/schemas/nullable.js +8 -5
- package/dist/core/codegen/schemas/nullable.js.map +1 -1
- package/dist/core/codegen/schemas/number.d.ts +7 -4
- package/dist/core/codegen/schemas/number.d.ts.map +1 -1
- package/dist/core/codegen/schemas/number.js +120 -176
- package/dist/core/codegen/schemas/number.js.map +1 -1
- package/dist/core/codegen/schemas/object.d.ts +8 -5
- package/dist/core/codegen/schemas/object.d.ts.map +1 -1
- package/dist/core/codegen/schemas/object.js +144 -231
- package/dist/core/codegen/schemas/object.js.map +1 -1
- package/dist/core/codegen/schemas/optional.d.ts +9 -6
- package/dist/core/codegen/schemas/optional.d.ts.map +1 -1
- package/dist/core/codegen/schemas/optional.js +23 -31
- package/dist/core/codegen/schemas/optional.js.map +1 -1
- package/dist/core/codegen/schemas/pipe.d.ts +8 -5
- package/dist/core/codegen/schemas/pipe.d.ts.map +1 -1
- package/dist/core/codegen/schemas/pipe.js +20 -27
- package/dist/core/codegen/schemas/pipe.js.map +1 -1
- package/dist/core/codegen/schemas/readonly.d.ts +8 -5
- package/dist/core/codegen/schemas/readonly.d.ts.map +1 -1
- package/dist/core/codegen/schemas/readonly.js +8 -5
- package/dist/core/codegen/schemas/readonly.js.map +1 -1
- package/dist/core/codegen/schemas/record.d.ts +8 -5
- package/dist/core/codegen/schemas/record.d.ts.map +1 -1
- package/dist/core/codegen/schemas/record.js +52 -65
- package/dist/core/codegen/schemas/record.js.map +1 -1
- package/dist/core/codegen/schemas/recursive-ref.d.ts +9 -6
- package/dist/core/codegen/schemas/recursive-ref.d.ts.map +1 -1
- package/dist/core/codegen/schemas/recursive-ref.js +44 -44
- package/dist/core/codegen/schemas/recursive-ref.js.map +1 -1
- package/dist/core/codegen/schemas/set.d.ts +8 -5
- package/dist/core/codegen/schemas/set.d.ts.map +1 -1
- package/dist/core/codegen/schemas/set.js +61 -73
- package/dist/core/codegen/schemas/set.js.map +1 -1
- package/dist/core/codegen/schemas/string-bool.d.ts +6 -3
- package/dist/core/codegen/schemas/string-bool.d.ts.map +1 -1
- package/dist/core/codegen/schemas/string-bool.js +22 -23
- package/dist/core/codegen/schemas/string-bool.js.map +1 -1
- package/dist/core/codegen/schemas/string.d.ts +8 -5
- package/dist/core/codegen/schemas/string.d.ts.map +1 -1
- package/dist/core/codegen/schemas/string.js +168 -207
- package/dist/core/codegen/schemas/string.js.map +1 -1
- package/dist/core/codegen/schemas/symbol.d.ts +7 -4
- package/dist/core/codegen/schemas/symbol.d.ts.map +1 -1
- package/dist/core/codegen/schemas/symbol.js +8 -4
- package/dist/core/codegen/schemas/symbol.js.map +1 -1
- package/dist/core/codegen/schemas/template-literal.d.ts +7 -4
- package/dist/core/codegen/schemas/template-literal.d.ts.map +1 -1
- package/dist/core/codegen/schemas/template-literal.js +12 -13
- package/dist/core/codegen/schemas/template-literal.js.map +1 -1
- package/dist/core/codegen/schemas/tuple.d.ts +8 -5
- package/dist/core/codegen/schemas/tuple.d.ts.map +1 -1
- package/dist/core/codegen/schemas/tuple.js +84 -94
- package/dist/core/codegen/schemas/tuple.js.map +1 -1
- package/dist/core/codegen/schemas/undefined.d.ts +7 -4
- package/dist/core/codegen/schemas/undefined.d.ts.map +1 -1
- package/dist/core/codegen/schemas/undefined.js +8 -4
- package/dist/core/codegen/schemas/undefined.js.map +1 -1
- package/dist/core/codegen/schemas/union.d.ts +8 -5
- package/dist/core/codegen/schemas/union.d.ts.map +1 -1
- package/dist/core/codegen/schemas/union.js +49 -69
- package/dist/core/codegen/schemas/union.js.map +1 -1
- package/dist/core/codegen/schemas/unknown.d.ts +7 -4
- package/dist/core/codegen/schemas/unknown.d.ts.map +1 -1
- package/dist/core/codegen/schemas/unknown.js +8 -4
- package/dist/core/codegen/schemas/unknown.js.map +1 -1
- package/dist/core/codegen/schemas/void.d.ts +7 -4
- package/dist/core/codegen/schemas/void.d.ts.map +1 -1
- package/dist/core/codegen/schemas/void.js +8 -4
- package/dist/core/codegen/schemas/void.js.map +1 -1
- package/dist/core/codegen/slow-path.d.ts +7 -4
- package/dist/core/codegen/slow-path.d.ts.map +1 -1
- package/dist/core/codegen/slow-path.js +71 -96
- package/dist/core/codegen/slow-path.js.map +1 -1
- package/dist/core/codegen/well-known-regex.d.ts +22 -19
- package/dist/core/codegen/well-known-regex.d.ts.map +1 -1
- package/dist/core/codegen/well-known-regex.js +127 -96
- package/dist/core/codegen/well-known-regex.js.map +1 -1
- package/dist/core/compile.d.ts +7 -4
- package/dist/core/compile.d.ts.map +1 -1
- package/dist/core/compile.js +48 -48
- package/dist/core/compile.js.map +1 -1
- package/dist/core/diagnostic.d.ts +38 -39
- package/dist/core/diagnostic.d.ts.map +1 -1
- package/dist/core/diagnostic.js +140 -164
- package/dist/core/diagnostic.js.map +1 -1
- package/dist/core/extract/checks.d.ts +18 -15
- package/dist/core/extract/checks.d.ts.map +1 -1
- package/dist/core/extract/checks.js +318 -311
- package/dist/core/extract/checks.js.map +1 -1
- package/dist/core/extract/effects.d.ts +13 -10
- package/dist/core/extract/effects.d.ts.map +1 -1
- package/dist/core/extract/effects.js +153 -222
- package/dist/core/extract/effects.js.map +1 -1
- package/dist/core/extract/extractors/any.d.ts +5 -2
- package/dist/core/extract/extractors/any.d.ts.map +1 -1
- package/dist/core/extract/extractors/any.js +5 -1
- package/dist/core/extract/extractors/any.js.map +1 -1
- package/dist/core/extract/extractors/array.d.ts +6 -3
- package/dist/core/extract/extractors/array.d.ts.map +1 -1
- package/dist/core/extract/extractors/array.js +25 -20
- package/dist/core/extract/extractors/array.js.map +1 -1
- package/dist/core/extract/extractors/bigint.d.ts +6 -3
- package/dist/core/extract/extractors/bigint.d.ts.map +1 -1
- package/dist/core/extract/extractors/bigint.js +66 -64
- package/dist/core/extract/extractors/bigint.js.map +1 -1
- package/dist/core/extract/extractors/boolean.d.ts +5 -2
- package/dist/core/extract/extractors/boolean.d.ts.map +1 -1
- package/dist/core/extract/extractors/boolean.js +7 -3
- package/dist/core/extract/extractors/boolean.js.map +1 -1
- package/dist/core/extract/extractors/catch.d.ts +6 -3
- package/dist/core/extract/extractors/catch.d.ts.map +1 -1
- package/dist/core/extract/extractors/catch.js +26 -17
- package/dist/core/extract/extractors/catch.js.map +1 -1
- package/dist/core/extract/extractors/date.d.ts +6 -3
- package/dist/core/extract/extractors/date.d.ts.map +1 -1
- package/dist/core/extract/extractors/date.js +42 -46
- package/dist/core/extract/extractors/date.js.map +1 -1
- package/dist/core/extract/extractors/default.d.ts +6 -3
- package/dist/core/extract/extractors/default.d.ts.map +1 -1
- package/dist/core/extract/extractors/default.js +20 -14
- package/dist/core/extract/extractors/default.js.map +1 -1
- package/dist/core/extract/extractors/enum.d.ts +5 -2
- package/dist/core/extract/extractors/enum.d.ts.map +1 -1
- package/dist/core/extract/extractors/enum.js +12 -13
- package/dist/core/extract/extractors/enum.js.map +1 -1
- package/dist/core/extract/extractors/file.d.ts +6 -3
- package/dist/core/extract/extractors/file.d.ts.map +1 -1
- package/dist/core/extract/extractors/file.js +34 -28
- package/dist/core/extract/extractors/file.js.map +1 -1
- package/dist/core/extract/extractors/intersection.d.ts +5 -2
- package/dist/core/extract/extractors/intersection.d.ts.map +1 -1
- package/dist/core/extract/extractors/intersection.js +13 -11
- package/dist/core/extract/extractors/intersection.js.map +1 -1
- package/dist/core/extract/extractors/lazy.d.ts +6 -3
- package/dist/core/extract/extractors/lazy.d.ts.map +1 -1
- package/dist/core/extract/extractors/lazy.js +21 -30
- package/dist/core/extract/extractors/lazy.js.map +1 -1
- package/dist/core/extract/extractors/literal.d.ts +5 -2
- package/dist/core/extract/extractors/literal.d.ts.map +1 -1
- package/dist/core/extract/extractors/literal.js +8 -1
- package/dist/core/extract/extractors/literal.js.map +1 -1
- package/dist/core/extract/extractors/map.d.ts +6 -3
- package/dist/core/extract/extractors/map.d.ts.map +1 -1
- package/dist/core/extract/extractors/map.js +10 -4
- package/dist/core/extract/extractors/map.js.map +1 -1
- package/dist/core/extract/extractors/nan.d.ts +5 -2
- package/dist/core/extract/extractors/nan.d.ts.map +1 -1
- package/dist/core/extract/extractors/nan.js +5 -1
- package/dist/core/extract/extractors/nan.js.map +1 -1
- package/dist/core/extract/extractors/never.d.ts +5 -2
- package/dist/core/extract/extractors/never.d.ts.map +1 -1
- package/dist/core/extract/extractors/never.js +5 -1
- package/dist/core/extract/extractors/never.js.map +1 -1
- package/dist/core/extract/extractors/null.d.ts +5 -2
- package/dist/core/extract/extractors/null.d.ts.map +1 -1
- package/dist/core/extract/extractors/null.js +5 -1
- package/dist/core/extract/extractors/null.js.map +1 -1
- package/dist/core/extract/extractors/nullable.d.ts +5 -2
- package/dist/core/extract/extractors/nullable.d.ts.map +1 -1
- package/dist/core/extract/extractors/nullable.js +7 -3
- package/dist/core/extract/extractors/nullable.js.map +1 -1
- package/dist/core/extract/extractors/number.d.ts +6 -3
- package/dist/core/extract/extractors/number.d.ts.map +1 -1
- package/dist/core/extract/extractors/number.js +35 -35
- package/dist/core/extract/extractors/number.js.map +1 -1
- package/dist/core/extract/extractors/object.d.ts +6 -3
- package/dist/core/extract/extractors/object.d.ts.map +1 -1
- package/dist/core/extract/extractors/object.js +49 -76
- package/dist/core/extract/extractors/object.js.map +1 -1
- package/dist/core/extract/extractors/optional.d.ts +5 -2
- package/dist/core/extract/extractors/optional.d.ts.map +1 -1
- package/dist/core/extract/extractors/optional.js +10 -12
- package/dist/core/extract/extractors/optional.js.map +1 -1
- package/dist/core/extract/extractors/pipe.d.ts +6 -3
- package/dist/core/extract/extractors/pipe.d.ts.map +1 -1
- package/dist/core/extract/extractors/pipe.js +40 -41
- package/dist/core/extract/extractors/pipe.js.map +1 -1
- package/dist/core/extract/extractors/readonly.d.ts +5 -2
- package/dist/core/extract/extractors/readonly.d.ts.map +1 -1
- package/dist/core/extract/extractors/readonly.js +10 -6
- package/dist/core/extract/extractors/readonly.js.map +1 -1
- package/dist/core/extract/extractors/record.d.ts +6 -3
- package/dist/core/extract/extractors/record.d.ts.map +1 -1
- package/dist/core/extract/extractors/record.js +24 -35
- package/dist/core/extract/extractors/record.js.map +1 -1
- package/dist/core/extract/extractors/set.d.ts +6 -3
- package/dist/core/extract/extractors/set.d.ts.map +1 -1
- package/dist/core/extract/extractors/set.js +36 -30
- package/dist/core/extract/extractors/set.js.map +1 -1
- package/dist/core/extract/extractors/string-bool.d.ts +7 -4
- package/dist/core/extract/extractors/string-bool.d.ts.map +1 -1
- package/dist/core/extract/extractors/string-bool.js +66 -84
- package/dist/core/extract/extractors/string-bool.js.map +1 -1
- package/dist/core/extract/extractors/string.d.ts +6 -3
- package/dist/core/extract/extractors/string.d.ts.map +1 -1
- package/dist/core/extract/extractors/string.js +34 -37
- package/dist/core/extract/extractors/string.js.map +1 -1
- package/dist/core/extract/extractors/symbol.d.ts +5 -2
- package/dist/core/extract/extractors/symbol.d.ts.map +1 -1
- package/dist/core/extract/extractors/symbol.js +5 -1
- package/dist/core/extract/extractors/symbol.js.map +1 -1
- package/dist/core/extract/extractors/template-literal.d.ts +6 -3
- package/dist/core/extract/extractors/template-literal.d.ts.map +1 -1
- package/dist/core/extract/extractors/template-literal.js +11 -6
- package/dist/core/extract/extractors/template-literal.js.map +1 -1
- package/dist/core/extract/extractors/tuple.d.ts +6 -3
- package/dist/core/extract/extractors/tuple.d.ts.map +1 -1
- package/dist/core/extract/extractors/tuple.js +10 -4
- package/dist/core/extract/extractors/tuple.js.map +1 -1
- package/dist/core/extract/extractors/undefined.d.ts +5 -2
- package/dist/core/extract/extractors/undefined.d.ts.map +1 -1
- package/dist/core/extract/extractors/undefined.js +5 -1
- package/dist/core/extract/extractors/undefined.js.map +1 -1
- package/dist/core/extract/extractors/union.d.ts +6 -3
- package/dist/core/extract/extractors/union.d.ts.map +1 -1
- package/dist/core/extract/extractors/union.js +38 -64
- package/dist/core/extract/extractors/union.js.map +1 -1
- package/dist/core/extract/extractors/unknown.d.ts +5 -2
- package/dist/core/extract/extractors/unknown.d.ts.map +1 -1
- package/dist/core/extract/extractors/unknown.js +5 -1
- package/dist/core/extract/extractors/unknown.js.map +1 -1
- package/dist/core/extract/extractors/void.d.ts +5 -2
- package/dist/core/extract/extractors/void.d.ts.map +1 -1
- package/dist/core/extract/extractors/void.js +5 -1
- package/dist/core/extract/extractors/void.js.map +1 -1
- package/dist/core/extract/fallback.d.ts +6 -3
- package/dist/core/extract/fallback.d.ts.map +1 -1
- package/dist/core/extract/fallback.js +21 -7
- package/dist/core/extract/fallback.js.map +1 -1
- package/dist/core/extract/index.d.ts +6 -4
- package/dist/core/extract/index.d.ts.map +1 -1
- package/dist/core/extract/index.js +15 -15
- package/dist/core/extract/index.js.map +1 -1
- package/dist/core/extract/registry.d.ts +39 -36
- package/dist/core/extract/registry.d.ts.map +1 -1
- package/dist/core/extract/registry.js +96 -123
- package/dist/core/extract/registry.js.map +1 -1
- package/dist/core/extract/types.d.ts +124 -120
- package/dist/core/extract/types.d.ts.map +1 -1
- package/dist/core/extract/types.js +0 -1
- package/dist/core/iife.d.ts +14 -15
- package/dist/core/iife.d.ts.map +1 -1
- package/dist/core/iife.js +182 -206
- package/dist/core/iife.js.map +1 -1
- package/dist/core/pipeline.d.ts +33 -30
- package/dist/core/pipeline.d.ts.map +1 -1
- package/dist/core/pipeline.js +67 -74
- package/dist/core/pipeline.js.map +1 -1
- package/dist/core/types.d.ts +430 -427
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +0 -5
- package/dist/discovery.d.ts +8 -5
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +31 -32
- package/dist/discovery.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/jit.d.ts +15 -42
- package/dist/jit.d.ts.map +1 -1
- package/dist/jit.js +187 -216
- package/dist/jit.js.map +1 -1
- package/dist/loader.d.ts +14 -11
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +226 -258
- package/dist/loader.js.map +1 -1
- package/dist/static-filter.d.ts +4 -1
- package/dist/static-filter.d.ts.map +1 -1
- package/dist/static-filter.js +240 -367
- package/dist/static-filter.js.map +1 -1
- package/dist/swc.d.ts +38 -35
- package/dist/swc.d.ts.map +1 -1
- package/dist/swc.js +83 -76
- package/dist/swc.js.map +1 -1
- package/dist/unplugin/bun.d.ts +5 -2
- package/dist/unplugin/bun.d.ts.map +1 -1
- package/dist/unplugin/bun.js +5 -1
- package/dist/unplugin/bun.js.map +1 -1
- package/dist/unplugin/dep-graph.d.ts +10 -7
- package/dist/unplugin/dep-graph.d.ts.map +1 -1
- package/dist/unplugin/dep-graph.js +216 -252
- package/dist/unplugin/dep-graph.js.map +1 -1
- package/dist/unplugin/disk-cache.d.ts +121 -92
- package/dist/unplugin/disk-cache.d.ts.map +1 -1
- package/dist/unplugin/disk-cache.js +425 -444
- package/dist/unplugin/disk-cache.js.map +1 -1
- package/dist/unplugin/edits.d.ts +15 -12
- package/dist/unplugin/edits.d.ts.map +1 -1
- package/dist/unplugin/edits.js +24 -37
- package/dist/unplugin/edits.js.map +1 -1
- package/dist/unplugin/esbuild.d.ts +5 -2
- package/dist/unplugin/esbuild.d.ts.map +1 -1
- package/dist/unplugin/esbuild.js +5 -1
- package/dist/unplugin/esbuild.js.map +1 -1
- package/dist/unplugin/farm.d.ts +5 -2
- package/dist/unplugin/farm.d.ts.map +1 -1
- package/dist/unplugin/farm.js +5 -1
- package/dist/unplugin/farm.js.map +1 -1
- package/dist/unplugin/hoist-compile.d.ts +14 -42
- package/dist/unplugin/hoist-compile.d.ts.map +1 -1
- package/dist/unplugin/hoist-compile.js +67 -112
- package/dist/unplugin/hoist-compile.js.map +1 -1
- package/dist/unplugin/hoist.d.ts +56 -54
- package/dist/unplugin/hoist.d.ts.map +1 -1
- package/dist/unplugin/hoist.js +945 -1170
- package/dist/unplugin/hoist.js.map +1 -1
- package/dist/unplugin/index.d.ts +5 -3
- package/dist/unplugin/index.d.ts.map +1 -1
- package/dist/unplugin/index.js +175 -250
- package/dist/unplugin/index.js.map +1 -1
- package/dist/unplugin/rolldown.d.ts +5 -2
- package/dist/unplugin/rolldown.d.ts.map +1 -1
- package/dist/unplugin/rolldown.js +5 -1
- package/dist/unplugin/rolldown.js.map +1 -1
- package/dist/unplugin/rollup.d.ts +5 -2
- package/dist/unplugin/rollup.d.ts.map +1 -1
- package/dist/unplugin/rollup.js +5 -1
- package/dist/unplugin/rollup.js.map +1 -1
- package/dist/unplugin/rsbuild.d.ts +6 -3
- package/dist/unplugin/rsbuild.d.ts.map +1 -1
- package/dist/unplugin/rsbuild.js +15 -11
- package/dist/unplugin/rsbuild.js.map +1 -1
- package/dist/unplugin/rspack.d.ts +5 -2
- package/dist/unplugin/rspack.d.ts.map +1 -1
- package/dist/unplugin/rspack.js +5 -1
- package/dist/unplugin/rspack.js.map +1 -1
- package/dist/unplugin/transform.d.ts +30 -27
- package/dist/unplugin/transform.d.ts.map +1 -1
- package/dist/unplugin/transform.js +433 -620
- package/dist/unplugin/transform.js.map +1 -1
- package/dist/unplugin/types.d.ts +189 -184
- package/dist/unplugin/types.d.ts.map +1 -1
- package/dist/unplugin/types.js +22 -18
- package/dist/unplugin/types.js.map +1 -1
- package/dist/unplugin/virtual.d.ts +11 -8
- package/dist/unplugin/virtual.d.ts.map +1 -1
- package/dist/unplugin/virtual.js +65 -83
- package/dist/unplugin/virtual.js.map +1 -1
- package/dist/unplugin/vite.d.ts +5 -2
- package/dist/unplugin/vite.d.ts.map +1 -1
- package/dist/unplugin/vite.js +5 -1
- package/dist/unplugin/vite.js.map +1 -1
- package/dist/unplugin/webpack.d.ts +5 -2
- package/dist/unplugin/webpack.d.ts.map +1 -1
- package/dist/unplugin/webpack.js +5 -1
- package/dist/unplugin/webpack.js.map +1 -1
- package/package.json +23 -14
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/core/extract/types.js.map +0 -1
- package/dist/core/types.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -1,490 +1,416 @@
|
|
|
1
|
-
import { fastTestSource, lookupWellKnownRegex, wellKnownRegexSourceName
|
|
1
|
+
import { fastTestSource, lookupWellKnownRegex, wellKnownRegexSourceName } from "./well-known-regex.js";
|
|
2
|
+
//#region src/core/codegen/context.ts
|
|
2
3
|
/** `var a,b;` declaration for a scope's temps, or "" when it allocated none. */
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
function declareFastTemps(scope) {
|
|
5
|
+
return scope.temps.length > 0 ? `var ${scope.temps.join(",")};` : "";
|
|
5
6
|
}
|
|
6
7
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return `((${value}=${g.input})${sentinel}${joiner}(${inner}))`;
|
|
8
|
+
* Fast check for a wrapper that compares its input against a sentinel and
|
|
9
|
+
* otherwise delegates to an inner schema — `optional` (`===undefined`),
|
|
10
|
+
* `nullable` (`===null`) and `default` (`!==undefined`).
|
|
11
|
+
*
|
|
12
|
+
* Written naively these read the input TWICE: once for the sentinel test and
|
|
13
|
+
* again inside the inner check (which may itself read it several more times —
|
|
14
|
+
* `typeof x==="string"&&x.length>=3&&x.length<=20`). V8's load elimination
|
|
15
|
+
* removes the repeats only while the access is monomorphic; on the polymorphic
|
|
16
|
+
* and megamorphic call sites real payloads produce (an array of objects with
|
|
17
|
+
* differing key order, anything out of `JSON.parse`) every repeat is a fresh
|
|
18
|
+
* megamorphic lookup. Binding the value to a local once is worth 1.1-1.7x on
|
|
19
|
+
* the whole object check when the optional key is present, and is neutral when
|
|
20
|
+
* it is absent.
|
|
21
|
+
*
|
|
22
|
+
* Only hoisted when the input is a property access; a bare local (an array
|
|
23
|
+
* element variable, a record value) is already a single load, so it keeps the
|
|
24
|
+
* shorter form and byte-identical output.
|
|
25
|
+
*/
|
|
26
|
+
function fastSentinelWrapper(g, innerIR, sentinel, joiner) {
|
|
27
|
+
if (!isPropertyAccess(g.input)) {
|
|
28
|
+
const inner = g.visit(innerIR);
|
|
29
|
+
return inner === null ? null : `(${g.input}${sentinel}${joiner}(${inner}))`;
|
|
30
|
+
}
|
|
31
|
+
const value = g.local("w");
|
|
32
|
+
const inner = g.visit(innerIR, { input: value });
|
|
33
|
+
if (inner === null) return null;
|
|
34
|
+
return `((${value}=${g.input})${sentinel}${joiner}(${inner}))`;
|
|
35
35
|
}
|
|
36
36
|
/** True for an expression that performs a property load (`x["a"]`, `x.a`, `x[0][1]`). */
|
|
37
37
|
function isPropertyAccess(expr) {
|
|
38
|
-
|
|
38
|
+
return expr.includes("[") || expr.includes(".");
|
|
39
39
|
}
|
|
40
|
-
// ─── Shared emit helpers (used by both slow-path and fast-path factories) ────
|
|
41
40
|
/** Allocate a fresh `__${prefix}_${n}` identifier and bump the shared counter. */
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
function emitTemp(ctx, prefix) {
|
|
42
|
+
return `__${prefix}_${ctx.counter++}`;
|
|
44
43
|
}
|
|
45
44
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return name;
|
|
45
|
+
* Host a zero-capture effect function (refine predicate, transform,
|
|
46
|
+
* overwrite) in the preamble and return its variable name. The inline
|
|
47
|
+
* `(${source})(x)` form evaluates the function expression — allocating a
|
|
48
|
+
* function object — on EVERY parse at every effect site, including inside
|
|
49
|
+
* the "zero-allocation" fast chain. V8's escape analysis erases that in
|
|
50
|
+
* optimized frames, but interpreter/baseline/deopt frames pay it, and the
|
|
51
|
+
* full source text re-parses as bytecode at each site. Zero-capture sources
|
|
52
|
+
* reference only their own parameters and safe globals by construction, so
|
|
53
|
+
* a single preamble binding is semantically identical. Deduped per schema
|
|
54
|
+
* by source text.
|
|
55
|
+
*/
|
|
56
|
+
function emitEffectFn(ctx, source) {
|
|
57
|
+
ctx.effectFnCache ??= /* @__PURE__ */ new Map();
|
|
58
|
+
const cached = ctx.effectFnCache.get(source);
|
|
59
|
+
if (cached !== void 0) return cached;
|
|
60
|
+
const name = `__ef_${ctx.counter++}`;
|
|
61
|
+
ctx.preamble.push(`var ${name}=(${source});`);
|
|
62
|
+
ctx.effectFnCache.set(source, name);
|
|
63
|
+
return name;
|
|
66
64
|
}
|
|
67
65
|
/**
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
throw new Error("effect has neither inlineable source nor a reference index");
|
|
82
|
-
}
|
|
83
|
-
return emitEffectFn(ctx, effect.source);
|
|
66
|
+
* Callable expression for a user callback — a refine predicate or a transform.
|
|
67
|
+
*
|
|
68
|
+
* A zero-capture callback is hosted from its source text; one that CAPTURES
|
|
69
|
+
* outer variables is called by reference through `__rf[N]` — the user's own
|
|
70
|
+
* function object, reached from the schema — instead of costing the schema its
|
|
71
|
+
* compiled path. The reference is aliased into a preamble binding rather than
|
|
72
|
+
* re-read per call, for the same reason call-invoked helpers are (a per-call
|
|
73
|
+
* array element load is not a foldable callee).
|
|
74
|
+
*/
|
|
75
|
+
function emitEffectCallable(ctx, effect) {
|
|
76
|
+
if (effect.refIndex !== void 0) return emitConstant(ctx, "rfn", `__rf[${effect.refIndex}]`);
|
|
77
|
+
if (effect.source === void 0) throw new Error("effect has neither inlineable source nor a reference index");
|
|
78
|
+
return emitEffectFn(ctx, effect.source);
|
|
84
79
|
}
|
|
85
80
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
return name;
|
|
81
|
+
* Pristine fallback delegate: declare `var __rfp_N=__rf[N].safeParse.bind(__rf[N]);`
|
|
82
|
+
* in the preamble and return the variable name. Generated code must NEVER read
|
|
83
|
+
* `__rf[N].safeParse` at parse time: `__zcMkv` installs the compiled safeParse as
|
|
84
|
+
* an OWN property on the original schema object, and whenever `__rf[N]` is that
|
|
85
|
+
* same object the read resolves to the compiled delegate itself — infinite
|
|
86
|
+
* recursion (RangeError on every parse). The fallback entry and the __zcMkv
|
|
87
|
+
* target ARE the same object in compile mode (schemaExpr is the compile()
|
|
88
|
+
* argument identifier) and the CLI emitter ((__src_X as any).schema); in
|
|
89
|
+
* autoDiscover mode they are two textually identical constructions that any
|
|
90
|
+
* downstream CSE/dedup transform (babel-plugin-zod-hoist in a field incident)
|
|
91
|
+
* collapses back into one. Capturing at IIFE evaluation — before the trailing
|
|
92
|
+
* `return __zcMkv(...)` mutates anything — pins zod's own implementation; the
|
|
93
|
+
* worst case under cross-validator merges is delegating to an equivalent
|
|
94
|
+
* compiled validator (whose own delegates were captured even earlier), never
|
|
95
|
+
* a cycle.
|
|
96
|
+
*/
|
|
97
|
+
function emitRfDelegate(ctx, refIndex) {
|
|
98
|
+
const name = `__rfp_${refIndex}`;
|
|
99
|
+
const decl = `var ${name}=__rf[${refIndex}].safeParse.bind(__rf[${refIndex}]);`;
|
|
100
|
+
if (!ctx.preamble.includes(decl)) ctx.preamble.push(decl);
|
|
101
|
+
return name;
|
|
109
102
|
}
|
|
110
103
|
/**
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const testSource = flags ? null : fastTestSource(pattern);
|
|
134
|
-
ctx.preamble.push(`var ${name}=new RegExp(${escapeString(testSource ?? pattern)}${flagsArg});`);
|
|
135
|
-
ctx.regexCache.set(cacheKey, name);
|
|
136
|
-
return name;
|
|
104
|
+
* Resolve a regex pattern to a runtime variable name.
|
|
105
|
+
* Lean mode short-circuits well-known patterns to virtual-module names so the
|
|
106
|
+
* bundler can dedup across files; everything else is cached + declared in the
|
|
107
|
+
* per-IIFE preamble exactly once per pattern.
|
|
108
|
+
*/
|
|
109
|
+
function emitRegex(ctx, prefix, pattern, flags) {
|
|
110
|
+
if (ctx.mode === "lean" && !flags) {
|
|
111
|
+
const wellKnown = lookupWellKnownRegex(pattern);
|
|
112
|
+
if (wellKnown !== null) {
|
|
113
|
+
ctx.usedHelpers.add(wellKnown);
|
|
114
|
+
return wellKnown;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const cacheKey = flags ? `${flags}\u0000${pattern}` : pattern;
|
|
118
|
+
const cached = ctx.regexCache.get(cacheKey);
|
|
119
|
+
if (cached) return cached;
|
|
120
|
+
const name = `__re_${prefix}_${ctx.counter++}`;
|
|
121
|
+
const flagsArg = flags ? `,${escapeString(flags)}` : "";
|
|
122
|
+
const testSource = flags ? null : fastTestSource(pattern);
|
|
123
|
+
ctx.preamble.push(`var ${name}=new RegExp(${escapeString(testSource ?? pattern)}${flagsArg});`);
|
|
124
|
+
ctx.regexCache.set(cacheKey, name);
|
|
125
|
+
return name;
|
|
137
126
|
}
|
|
138
127
|
/**
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return name;
|
|
128
|
+
* Resolve the ORIGINAL `/source/flags` pattern string of a regex for issue
|
|
129
|
+
* reporting. Only needed when emitRegex swapped in a faster equivalent test
|
|
130
|
+
* pattern (the runtime regex's toString() would leak the rewrite). Lean mode
|
|
131
|
+
* references the shared `<name>Src` virtual export so the original pattern
|
|
132
|
+
* stays a single bundle-wide string; inline mode declares it once per IIFE.
|
|
133
|
+
*/
|
|
134
|
+
function emitRegexSourceString(ctx, pattern) {
|
|
135
|
+
if (ctx.mode === "lean") {
|
|
136
|
+
const srcName = wellKnownRegexSourceName(pattern);
|
|
137
|
+
if (srcName !== null) {
|
|
138
|
+
ctx.usedHelpers.add(srcName);
|
|
139
|
+
return srcName;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const cacheKey = `src\u0000${pattern}`;
|
|
143
|
+
const cached = ctx.regexCache.get(cacheKey);
|
|
144
|
+
if (cached) return cached;
|
|
145
|
+
const name = `__res_${ctx.counter++}`;
|
|
146
|
+
ctx.preamble.push(`var ${name}=${escapeString(`/${pattern}/`)};`);
|
|
147
|
+
ctx.regexCache.set(cacheKey, name);
|
|
148
|
+
return name;
|
|
161
149
|
}
|
|
162
150
|
/**
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return name;
|
|
151
|
+
* Declare a constant value in the preamble and return its variable name,
|
|
152
|
+
* reusing an earlier declaration of the SAME initializer.
|
|
153
|
+
*
|
|
154
|
+
* Value tables are reached from both halves of a validator — an enum's `Set`
|
|
155
|
+
* from its fast check and again from its slow walk, a strict shape's key table
|
|
156
|
+
* likewise — and repeat across sibling properties that share a value list. One
|
|
157
|
+
* declaration per USE emitted the payload two or four times: measured 17% of a
|
|
158
|
+
* 20-value enum schema's generated bytes, 16% for an object with two identical
|
|
159
|
+
* enums. Keyed by initializer text, so only identical payloads collapse.
|
|
160
|
+
*/
|
|
161
|
+
function emitConstant(ctx, prefix, initializer) {
|
|
162
|
+
ctx.valueCache ??= /* @__PURE__ */ new Map();
|
|
163
|
+
const cached = ctx.valueCache.get(initializer);
|
|
164
|
+
if (cached !== void 0) return cached;
|
|
165
|
+
const name = `__${prefix}_${ctx.counter++}`;
|
|
166
|
+
ctx.preamble.push(`var ${name}=${initializer};`);
|
|
167
|
+
ctx.valueCache.set(initializer, name);
|
|
168
|
+
return name;
|
|
182
169
|
}
|
|
183
170
|
/** Declare a `new Set([...])` in the preamble and return its variable name. */
|
|
184
|
-
|
|
185
|
-
|
|
171
|
+
function emitSet(ctx, prefix, values) {
|
|
172
|
+
return emitConstant(ctx, `set_${prefix}`, `new Set(${JSON.stringify([...values])})`);
|
|
186
173
|
}
|
|
187
174
|
/**
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
175
|
+
* Shape-key count at or below which the unknown-key pass compares with an
|
|
176
|
+
* inline `===` chain rather than a hashed lookup.
|
|
177
|
+
*
|
|
178
|
+
* This is deliberately NOT {@link ENUM_INLINE_THRESHOLD}: the two look alike but
|
|
179
|
+
* are different workloads. An enum compares schema literals against arbitrary
|
|
180
|
+
* INPUT strings, which may be long, share prefixes, and are not necessarily
|
|
181
|
+
* internalized — so a hashed set earns its keep quickly. A shape-key test
|
|
182
|
+
* compares them against keys arriving from `for-in`, i.e. the object's own
|
|
183
|
+
* internalized key strings, so every arm of the chain is a pointer compare that
|
|
184
|
+
* V8 predicts perfectly, while `table[k]` / `set.has(k)` pays a string hash and
|
|
185
|
+
* probe per key.
|
|
186
|
+
*
|
|
187
|
+
* Measured over a strict object's for-in pass (JSON-parsed input, 8 rotated
|
|
188
|
+
* shapes), `===` chain vs the previous `{k:1}` table: 3.7x at 6 keys, 3.8x at
|
|
189
|
+
* 10, 3.1x at 20, 3.1x at 48 — the chain still leads at 64 (283 ns vs 690) and
|
|
190
|
+
* only loses past ~96, where `Set.has` (not the table, which never wins at any
|
|
191
|
+
* size) takes over. 64 sits below that crossover and above any realistic shape.
|
|
192
|
+
*/
|
|
193
|
+
const KEY_MEMBERSHIP_INLINE_THRESHOLD = 64;
|
|
207
194
|
/**
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return keys.map((k) => `${keyVar}===${escapeString(k)}`).join("||");
|
|
221
|
-
}
|
|
222
|
-
return `${emitSet(ctx, "ks", keys)}.has(${keyVar})`;
|
|
195
|
+
* Boolean membership test for one key variable against a fixed key list.
|
|
196
|
+
* Empty list recognizes nothing.
|
|
197
|
+
*
|
|
198
|
+
* `Set.has` is the large-shape fallback rather than a `{key:1}` object table:
|
|
199
|
+
* the table is also `__proto__`-hostile (an own `__proto__` key cannot be set
|
|
200
|
+
* by an object literal, so that key would silently read as unknown), which the
|
|
201
|
+
* Set has no trouble with.
|
|
202
|
+
*/
|
|
203
|
+
function keyMembershipTest(ctx, keys, keyVar) {
|
|
204
|
+
if (keys.length === 0) return "false";
|
|
205
|
+
if (keys.length <= 64) return keys.map((k) => `${keyVar}===${escapeString(k)}`).join("||");
|
|
206
|
+
return `${emitSet(ctx, "ks", keys)}.has(${keyVar})`;
|
|
223
207
|
}
|
|
224
208
|
/**
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
209
|
+
* Enum values at or below this count use inline === checks instead of Set.has().
|
|
210
|
+
* Measured on V8: for ≤5 values, an === chain beats Set.has by up to ~3x with
|
|
211
|
+
* realistic (distinct-prefix, JSON-parsed) values — V8 internalizes strings on
|
|
212
|
+
* successful comparison, making subsequent arms pointer-equality — and is no
|
|
213
|
+
* worse than Set.has even with adversarial shared-prefix values.
|
|
214
|
+
*/
|
|
215
|
+
const ENUM_INLINE_THRESHOLD = 5;
|
|
232
216
|
const CHECK_PRIORITY = {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
// String prefix/suffix (O(prefix/suffix length))
|
|
252
|
-
starts_with: 40,
|
|
253
|
-
ends_with: 41,
|
|
254
|
-
// String search (O(n·m) worst case)
|
|
255
|
-
includes: 42,
|
|
256
|
-
// Regex (most expensive)
|
|
257
|
-
string_format: 50,
|
|
217
|
+
min_length: 10,
|
|
218
|
+
max_length: 11,
|
|
219
|
+
length_equals: 12,
|
|
220
|
+
min_size: 13,
|
|
221
|
+
max_size: 14,
|
|
222
|
+
number_format: 15,
|
|
223
|
+
greater_than: 20,
|
|
224
|
+
less_than: 21,
|
|
225
|
+
bigint_greater_than: 20,
|
|
226
|
+
bigint_less_than: 21,
|
|
227
|
+
date_greater_than: 22,
|
|
228
|
+
date_less_than: 23,
|
|
229
|
+
multiple_of: 30,
|
|
230
|
+
bigint_multiple_of: 30,
|
|
231
|
+
starts_with: 40,
|
|
232
|
+
ends_with: 41,
|
|
233
|
+
includes: 42,
|
|
234
|
+
string_format: 50
|
|
258
235
|
};
|
|
259
|
-
|
|
260
|
-
|
|
236
|
+
function escapeString(s) {
|
|
237
|
+
return JSON.stringify(s);
|
|
261
238
|
}
|
|
262
239
|
/**
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
// JSON.stringify maps NaN/±Infinity to "null"; emit them as JS expressions so a
|
|
274
|
-
// non-finite numeric literal round-trips (z.literal(Infinity) must compare
|
|
275
|
-
// against Infinity, not null). String(NaN)="NaN", String(Infinity)="Infinity",
|
|
276
|
-
// String(-Infinity)="-Infinity" — all valid JS that evaluate to the value.
|
|
277
|
-
if (typeof v === "number" && !Number.isFinite(v))
|
|
278
|
-
return String(v);
|
|
279
|
-
return JSON.stringify(v);
|
|
240
|
+
* JS source for a primitive literal value (literal schemas, discriminator
|
|
241
|
+
* case labels). JSON.stringify covers string/number/boolean/null; bigint
|
|
242
|
+
* needs the `n` suffix (JSON.stringify throws and String(5n) renders a
|
|
243
|
+
* number literal that never strict-equals a bigint); undefined isn't JSON.
|
|
244
|
+
*/
|
|
245
|
+
function literalToJs(v) {
|
|
246
|
+
if (typeof v === "bigint") return `${v}n`;
|
|
247
|
+
if (v === void 0) return "undefined";
|
|
248
|
+
if (typeof v === "number" && !Number.isFinite(v)) return String(v);
|
|
249
|
+
return JSON.stringify(v);
|
|
280
250
|
}
|
|
281
251
|
/**
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const CALL_INVOKED_HELPERS = new Set(["__zcHop"]);
|
|
252
|
+
* Helpers that generated code invokes through `Function.prototype.call`, and
|
|
253
|
+
* which therefore must be aliased into a module-local binding in lean mode.
|
|
254
|
+
*
|
|
255
|
+
* V8 folds a local `const` callee into a constant and inlines straight through
|
|
256
|
+
* `x.call(...)`; an IMPORTED binding is a cell it will not fold, so the same
|
|
257
|
+
* expression stays a generic property load plus a generic call — measured 4.5x
|
|
258
|
+
* (5 keys) to 6.5x (20 keys) slower on the record fast path, 35.9 ns vs 7.2 ns
|
|
259
|
+
* for a 5-key record. Aliasing the import into the IIFE recovers all of it
|
|
260
|
+
* (7.4 ns). A DIRECT call to an imported function (`__zcFsr(v,s)`) is not
|
|
261
|
+
* penalized — measured identical — and neither is an imported RegExp receiver,
|
|
262
|
+
* so only the `.call` sites are listed here.
|
|
263
|
+
*/
|
|
264
|
+
const CALL_INVOKED_HELPERS = /* @__PURE__ */ new Set(["__zcHop"]);
|
|
295
265
|
/**
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
else if (!ctx.preamble.includes(decl)) {
|
|
307
|
-
ctx.preamble.push(decl);
|
|
308
|
-
}
|
|
309
|
-
return name;
|
|
266
|
+
* Reference a shared runtime helper (e.g. __zcFsr) from generated code.
|
|
267
|
+
* Lean mode: registers it for the `virtual:zod-compiler/runtime` import.
|
|
268
|
+
* Inline mode: declares it once in the per-IIFE preamble.
|
|
269
|
+
*/
|
|
270
|
+
function emitRuntimeHelper(ctx, name, decl) {
|
|
271
|
+
if (ctx.mode === "lean") {
|
|
272
|
+
ctx.usedHelpers.add(name);
|
|
273
|
+
if (CALL_INVOKED_HELPERS.has(name)) return emitConstant(ctx, "lh", name);
|
|
274
|
+
} else if (!ctx.preamble.includes(decl)) ctx.preamble.push(decl);
|
|
275
|
+
return name;
|
|
310
276
|
}
|
|
311
277
|
/**
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
return `${parentPath.slice(0, -1)},${segExpr}]`;
|
|
327
|
-
}
|
|
328
|
-
return `${parentPath}.concat(${segExpr})`;
|
|
278
|
+
* Extend a path expression with one or more scalar segment expressions
|
|
279
|
+
* (escaped string literals, numeric literals, or loop-variable names).
|
|
280
|
+
*
|
|
281
|
+
* Path expressions are only ever composed by these helpers starting from the
|
|
282
|
+
* `[]` root, so any path that looks like an array literal IS one — the new
|
|
283
|
+
* segment is spliced in to keep issue paths a single array allocation
|
|
284
|
+
* (`["data","items",__i_7]`) instead of an allocation per nesting level
|
|
285
|
+
* (`["data"].concat("items").concat(__i_7)`). Opaque expressions fall back
|
|
286
|
+
* to .concat().
|
|
287
|
+
*/
|
|
288
|
+
function extendPath(parentPath, segExpr) {
|
|
289
|
+
if (parentPath === "[]") return `[${segExpr}]`;
|
|
290
|
+
if (parentPath.startsWith("[") && parentPath.endsWith("]")) return `${parentPath.slice(0, -1)},${segExpr}]`;
|
|
291
|
+
return `${parentPath}.concat(${segExpr})`;
|
|
329
292
|
}
|
|
330
293
|
/** Extend a path expression with a static string key. */
|
|
331
|
-
|
|
332
|
-
|
|
294
|
+
function extendStaticPath(parentPath, key) {
|
|
295
|
+
return extendPath(parentPath, escapeString(key));
|
|
333
296
|
}
|
|
334
297
|
/** Extend a path expression with a numeric index. */
|
|
335
|
-
|
|
336
|
-
|
|
298
|
+
function extendStaticPathIndex(parentPath, index) {
|
|
299
|
+
return extendPath(parentPath, String(index));
|
|
337
300
|
}
|
|
338
301
|
/**
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
302
|
+
* A superRefine callback receives zod's payload, whose `value` is public,
|
|
303
|
+
* typed, writable API ($RefinementCtx extends ParsePayload) — so any node
|
|
304
|
+
* carrying one MAY rewrite its value and must be treated as mutating. Which
|
|
305
|
+
* callbacks actually do is undecidable here; the emitted fast check settles it
|
|
306
|
+
* at runtime by refusing when the value changed (see ZC_SR_OK_DECL), so a
|
|
307
|
+
* non-mutating callback still exits through the fast path.
|
|
308
|
+
*/
|
|
346
309
|
function hasSuperRefine(checks) {
|
|
347
|
-
|
|
310
|
+
return checks !== void 0 && checks.some((c) => c.kind === "super_refine_effect");
|
|
348
311
|
}
|
|
349
312
|
/**
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
Object.values(ir.properties).some((p) => hasMutation(p)));
|
|
388
|
-
case "array":
|
|
389
|
-
return hasSuperRefine(ir.checks) || hasMutation(ir.element);
|
|
390
|
-
case "tuple":
|
|
391
|
-
return ir.items.some(hasMutation) || (ir.rest !== null && hasMutation(ir.rest));
|
|
392
|
-
case "record":
|
|
393
|
-
return hasMutation(ir.valueType);
|
|
394
|
-
case "optional":
|
|
395
|
-
case "nullable":
|
|
396
|
-
case "readonly":
|
|
397
|
-
case "recursionTarget":
|
|
398
|
-
return hasMutation(ir.inner);
|
|
399
|
-
case "union":
|
|
400
|
-
case "discriminatedUnion":
|
|
401
|
-
return ir.options.some(hasMutation);
|
|
402
|
-
case "intersection":
|
|
403
|
-
return hasMutation(ir.left) || hasMutation(ir.right);
|
|
404
|
-
case "pipe":
|
|
405
|
-
return hasMutation(ir.in) || hasMutation(ir.out);
|
|
406
|
-
case "set":
|
|
407
|
-
return hasMutation(ir.valueType);
|
|
408
|
-
case "map":
|
|
409
|
-
return hasMutation(ir.keyType) || hasMutation(ir.valueType);
|
|
410
|
-
case "file":
|
|
411
|
-
return false;
|
|
412
|
-
default:
|
|
413
|
-
return false;
|
|
414
|
-
}
|
|
313
|
+
* Check if a SchemaIR tree produces output that is not the input itself —
|
|
314
|
+
* either value-mutating operations (coerce, default, catch, overwrite) that
|
|
315
|
+
* write back to the input expression, or a strip object that rebuilds a fresh
|
|
316
|
+
* object from its known keys. Used by container generators to decide whether to
|
|
317
|
+
* clone (so the rebuilt/mutated value never writes through to the caller's
|
|
318
|
+
* input), by generateValidator to keep such schemas off the by-reference fast
|
|
319
|
+
* path, and by the shared-walk dedup + intersection extractor to exclude them.
|
|
320
|
+
*/
|
|
321
|
+
function hasMutation(ir) {
|
|
322
|
+
switch (ir.type) {
|
|
323
|
+
case "string": return ir.coerce === true || hasSuperRefine(ir.checks) || ir.checks.some((c) => c.kind === "overwrite_effect" || c.kind === "string_format" && c.format === "url");
|
|
324
|
+
case "number": return ir.coerce === true || hasSuperRefine(ir.checks);
|
|
325
|
+
case "boolean":
|
|
326
|
+
case "bigint":
|
|
327
|
+
case "date": return ir.coerce === true;
|
|
328
|
+
case "default":
|
|
329
|
+
case "catch":
|
|
330
|
+
case "effect":
|
|
331
|
+
case "fallback":
|
|
332
|
+
case "stringBool": return true;
|
|
333
|
+
case "object": return ir.stripUnknownKeys === true || hasSuperRefine(ir.checks) || ir.catchall !== void 0 && hasMutation(ir.catchall) || Object.values(ir.properties).some((p) => hasMutation(p));
|
|
334
|
+
case "array": return hasSuperRefine(ir.checks) || hasMutation(ir.element);
|
|
335
|
+
case "tuple": return ir.items.some(hasMutation) || ir.rest !== null && hasMutation(ir.rest);
|
|
336
|
+
case "record": return hasMutation(ir.valueType);
|
|
337
|
+
case "optional":
|
|
338
|
+
case "nullable":
|
|
339
|
+
case "readonly":
|
|
340
|
+
case "recursionTarget": return hasMutation(ir.inner);
|
|
341
|
+
case "union":
|
|
342
|
+
case "discriminatedUnion": return ir.options.some(hasMutation);
|
|
343
|
+
case "intersection": return hasMutation(ir.left) || hasMutation(ir.right);
|
|
344
|
+
case "pipe": return hasMutation(ir.in) || hasMutation(ir.out);
|
|
345
|
+
case "set": return hasMutation(ir.valueType);
|
|
346
|
+
case "map": return hasMutation(ir.keyType) || hasMutation(ir.valueType);
|
|
347
|
+
case "file": return false;
|
|
348
|
+
default: return false;
|
|
349
|
+
}
|
|
415
350
|
}
|
|
416
351
|
/**
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
352
|
+
* Is a defaulted property's key guaranteed to appear in the stripped output?
|
|
353
|
+
*
|
|
354
|
+
* Distinct from {@link rejectsUndefined}, which asks whether `undefined` is
|
|
355
|
+
* REJECTED — a `.default()` accepts it and yet still produces a defined value, so
|
|
356
|
+
* only this question earns the key a slot in the output object literal. The two
|
|
357
|
+
* answers coincide everywhere else.
|
|
358
|
+
*
|
|
359
|
+
* Sound for both branches of a default: the substituted value is defined
|
|
360
|
+
* (`alwaysDefined`, checked against the schema at extraction time), and the inner
|
|
361
|
+
* branch runs only when `input[key] !== undefined`, which implies `key in input`
|
|
362
|
+
* — so zod's presence test keeps the key whatever the inner produced.
|
|
363
|
+
*/
|
|
364
|
+
function outputAlwaysDefined(ir) {
|
|
365
|
+
return ir.type === "default" ? ir.alwaysDefined === true : rejectsUndefined(ir);
|
|
431
366
|
}
|
|
432
367
|
/**
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
case "intersection":
|
|
471
|
-
return rejectsUndefined(ir.left) || rejectsUndefined(ir.right);
|
|
472
|
-
case "nullable":
|
|
473
|
-
case "readonly":
|
|
474
|
-
case "recursionTarget":
|
|
475
|
-
return rejectsUndefined(ir.inner);
|
|
476
|
-
default:
|
|
477
|
-
// optional / any / unknown / undefined / void / default / catch /
|
|
478
|
-
// fallback / effect / pipe / recursiveRef — each can yield undefined,
|
|
479
|
-
// or is opaque enough that we must not assume otherwise.
|
|
480
|
-
return false;
|
|
481
|
-
}
|
|
368
|
+
* Does this schema reject `undefined` outright?
|
|
369
|
+
*
|
|
370
|
+
* Read as "can this slot be ABSENT from the input" by the tuple build, whose
|
|
371
|
+
* output length depends on it — zod marks a defaulted or optional item
|
|
372
|
+
* `optin: "optional"` and accepts a shorter array. Conservative: anything that
|
|
373
|
+
* might accept, produce, or default to `undefined` answers false.
|
|
374
|
+
*/
|
|
375
|
+
function rejectsUndefined(ir) {
|
|
376
|
+
switch (ir.type) {
|
|
377
|
+
case "string":
|
|
378
|
+
case "number":
|
|
379
|
+
case "boolean":
|
|
380
|
+
case "bigint":
|
|
381
|
+
case "date": return ir.coerce !== true;
|
|
382
|
+
case "symbol":
|
|
383
|
+
case "null":
|
|
384
|
+
case "nan":
|
|
385
|
+
case "never":
|
|
386
|
+
case "enum":
|
|
387
|
+
case "object":
|
|
388
|
+
case "array":
|
|
389
|
+
case "tuple":
|
|
390
|
+
case "record":
|
|
391
|
+
case "set":
|
|
392
|
+
case "map":
|
|
393
|
+
case "file":
|
|
394
|
+
case "templateLiteral":
|
|
395
|
+
case "discriminatedUnion":
|
|
396
|
+
case "stringBool": return true;
|
|
397
|
+
case "literal": return !ir.values.includes(void 0);
|
|
398
|
+
case "union": return ir.options.every(rejectsUndefined);
|
|
399
|
+
case "intersection": return rejectsUndefined(ir.left) || rejectsUndefined(ir.right);
|
|
400
|
+
case "nullable":
|
|
401
|
+
case "readonly":
|
|
402
|
+
case "recursionTarget": return rejectsUndefined(ir.inner);
|
|
403
|
+
default: return false;
|
|
404
|
+
}
|
|
482
405
|
}
|
|
483
406
|
/**
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
407
|
+
* Sort comparator for CheckIR: cheapest/most-discriminating checks first.
|
|
408
|
+
* Used by fast-path generators after filtering out refine_effect entries.
|
|
409
|
+
*/
|
|
410
|
+
function checkPriority(a, b) {
|
|
411
|
+
return (CHECK_PRIORITY[a.kind] ?? 99) - (CHECK_PRIORITY[b.kind] ?? 99);
|
|
489
412
|
}
|
|
413
|
+
//#endregion
|
|
414
|
+
export { ENUM_INLINE_THRESHOLD, KEY_MEMBERSHIP_INLINE_THRESHOLD, checkPriority, declareFastTemps, emitConstant, emitEffectCallable, emitEffectFn, emitRegex, emitRegexSourceString, emitRfDelegate, emitRuntimeHelper, emitSet, emitTemp, escapeString, extendPath, extendStaticPath, extendStaticPathIndex, fastSentinelWrapper, hasMutation, keyMembershipTest, literalToJs, outputAlwaysDefined, rejectsUndefined };
|
|
415
|
+
|
|
490
416
|
//# sourceMappingURL=context.js.map
|