zod-compiler 1.2.0 → 1.3.0
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 +51 -46
- package/dist/core/codegen/issue-decls.d.ts +10 -0
- package/dist/core/codegen/issue-decls.d.ts.map +1 -1
- package/dist/core/codegen/issue-decls.js +11 -0
- package/dist/core/codegen/issue-decls.js.map +1 -1
- package/dist/core/codegen/schemas/record.d.ts.map +1 -1
- package/dist/core/codegen/schemas/record.js +20 -7
- package/dist/core/codegen/schemas/record.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**Compile Zod schemas into zero-overhead validation functions at build time.**
|
|
4
4
|
|
|
5
|
-
Keep your existing Zod schemas. Get **2-
|
|
5
|
+
Keep your existing Zod schemas. Get **2-75x faster** validation. No code changes required.
|
|
6
6
|
|
|
7
7
|
- [What Gets Compiled](#what-gets-compiled)
|
|
8
8
|
- [Schema Hoisting](#schema-hoisting)
|
|
@@ -421,19 +421,24 @@ Output:
|
|
|
421
421
|
```
|
|
422
422
|
src/schemas.ts
|
|
423
423
|
|
|
424
|
-
CreateUserSchema
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
424
|
+
CreateUserSchema — 100% compiled (4/4 nodes) | Fast Path: eligible
|
|
425
|
+
└─ ✓ object
|
|
426
|
+
├─ ✓ string .name
|
|
427
|
+
├─ ✓ string .email
|
|
428
|
+
├─ ✓ number .age
|
|
429
|
+
└─ ✓ enum .role
|
|
430
|
+
|
|
431
|
+
OrderSchema — 67% compiled (2/3 nodes) | Fast Path: ineligible (fallback (transform))
|
|
432
|
+
└─ ✓ object
|
|
433
|
+
├─ ✓ string .id
|
|
434
|
+
└─ ✓ object .metadata
|
|
435
|
+
├─ ✓ string .metadata.region
|
|
436
|
+
└─ ✗ fallback .metadata.audit (transform)
|
|
437
|
+
hint: Extract transform into a separate post-processing step
|
|
438
|
+
|
|
439
|
+
Fallbacks:
|
|
440
|
+
✗ .metadata.audit — transform
|
|
441
|
+
Extract transform into a separate post-processing step
|
|
437
442
|
```
|
|
438
443
|
|
|
439
444
|
### CI Integration
|
|
@@ -454,7 +459,7 @@ npx zod-compiler check src/schemas.ts --json --fail-under 80
|
|
|
454
459
|
|
|
455
460
|
## What Gets Compiled
|
|
456
461
|
|
|
457
|
-
### Fully Compiled (2-
|
|
462
|
+
### Fully Compiled (2-75x faster)
|
|
458
463
|
|
|
459
464
|
`string`, `number`, `bigint`, `boolean`, `null`, `undefined`, `any`, `unknown`, `literal`, `enum`, `stringbool`, `date`, `file`, `object`, `strictObject` / `.strict()`, `looseObject`, `array`, `tuple`, `record`, `set`, `map`, `union`, `discriminatedUnion`, `intersection`, `pipe` (non-transform), `optional`, `nullable`, `readonly`, `default`, `catch`, `coerce`, `templateLiteral`, `symbol`, `void`, `nan`, `never`, `lazy` (self-recursive), `transform` / `refine` (zero-capture — see below)
|
|
460
465
|
|
|
@@ -490,37 +495,37 @@ compiles; `z.string().transform((s) => s + suffix)` falls back (it captures
|
|
|
490
495
|
|
|
491
496
|
| Scenario | Zod v3 | Zod v4 | **zod-compiler** | Typia | AJV | vs Zod v4 |
|
|
492
497
|
| ------------------------------------------------- | ------ | ------ | ---------------- | ----- | ----- | --------- |
|
|
493
|
-
| simple string |
|
|
494
|
-
| string (min/max) |
|
|
495
|
-
| number (int+positive) |
|
|
496
|
-
| enum |
|
|
497
|
-
| bigint (min/max) |
|
|
498
|
-
| tuple [string, int, bool] |
|
|
499
|
-
| record\<string, number\> | 3.2M | 2.8M | **
|
|
500
|
-
| set\<string\> (5 items) | 3.7M | 2.
|
|
501
|
-
| set\<string\> (20 items) | 1.
|
|
502
|
-
| map\<string, number\> (5 entries) |
|
|
503
|
-
| map\<string, number\> (20 entries) |
|
|
504
|
-
| pipe (non-transform) | 8.8M | 5.
|
|
505
|
-
| discriminatedUnion (3 variants) | 3.
|
|
506
|
-
| strict object (DB row) | 1.
|
|
507
|
-
| medium object (valid) | 1.9M | 2.4M | **
|
|
508
|
-
| medium object (invalid) |
|
|
509
|
-
| large object (10 items) |
|
|
510
|
-
| large object (100 items) | 13K | 18K | **1.
|
|
511
|
-
| recursive tree (7 nodes) |
|
|
512
|
-
| recursive tree (121 nodes) |
|
|
513
|
-
| event log (combined) |
|
|
514
|
-
| object with transform (zero-capture) | 1.
|
|
515
|
-
| array 10 × transform (zero-capture) |
|
|
516
|
-
| array 50 × transform (zero-capture) |
|
|
517
|
-
| object with captured transform (partial fallback) | 1.4M | 6.
|
|
518
|
-
|
|
519
|
-
_ops/s, higher is better. "—" = not supported by the library. Measured with `vitest bench` on Apple
|
|
520
|
-
|
|
521
|
-
Performance scales with schema complexity. Nested objects and arrays see the biggest gains because zod-compiler eliminates per-node traversal overhead. `discriminatedUnion` uses O(1) `switch` dispatch instead of Zod's sequential trial. The invalid-input row is large because failed `safeParse` defers error materialization until `.error` is read. Zero-capture `transform`/`refine` callbacks are compiled (3-
|
|
522
|
-
|
|
523
|
-
`parse()` (throwing API) rides a zero-allocation fast path: medium object 2.2M → 9.
|
|
498
|
+
| simple string | 11.8M | 13.5M | **15.6M** | 15.8M | 16.4M | 1.2x |
|
|
499
|
+
| string (min/max) | 11.9M | 7.9M | **17.2M** | 17.7M | 15.5M | 2.2x |
|
|
500
|
+
| number (int+positive) | 12.1M | 7.6M | **15.9M** | 17.0M | 16.7M | 2.1x |
|
|
501
|
+
| enum | 10.8M | 11.8M | **15.3M** | 16.8M | 16.7M | 1.3x |
|
|
502
|
+
| bigint (min/max) | 10.9M | 7.2M | **15.4M** | — | — | 2.1x |
|
|
503
|
+
| tuple [string, int, bool] | 6.0M | 6.7M | **16.3M** | 17.4M | 16.5M | 2.4x |
|
|
504
|
+
| record\<string, number\> | 3.2M | 2.8M | **8.2M** | 11.9M | 15.6M | 2.9x |
|
|
505
|
+
| set\<string\> (5 items) | 3.7M | 2.3M | **14.6M** | — | — | 6.3x |
|
|
506
|
+
| set\<string\> (20 items) | 1.3M | 702K | **11.9M** | — | — | **17x** |
|
|
507
|
+
| map\<string, number\> (5 entries) | 2.1M | 1.3M | **13.0M** | — | — | 9.7x |
|
|
508
|
+
| map\<string, number\> (20 entries) | 643K | 352K | **8.4M** | — | — | **24x** |
|
|
509
|
+
| pipe (non-transform) | 8.8M | 5.9M | **15.7M** | — | — | 2.7x |
|
|
510
|
+
| discriminatedUnion (3 variants) | 3.3M | 4.3M | **15.1M** | 16.4M | 8.0M | 3.5x |
|
|
511
|
+
| strict object (DB row) | 1.9M | 3.1M | **7.0M** | — | — | 2.3x |
|
|
512
|
+
| medium object (valid) | 1.9M | 2.4M | **10.1M** | 11.8M | 7.5M | 4.2x |
|
|
513
|
+
| medium object (invalid) | 553K | 81K | **6.1M** | 3.1M | 8.0M | **75x** |
|
|
514
|
+
| large object (10 items) | 124K | 169K | **8.0M** | 6.1M | 1.2M | **47x** |
|
|
515
|
+
| large object (100 items) | 13K | 18K | **1.4M** | 1.3M | 122K | **74x** |
|
|
516
|
+
| recursive tree (7 nodes) | 583K | 2.1M | **12.8M** | 12.4M | 4.5M | 6.0x |
|
|
517
|
+
| recursive tree (121 nodes) | 33K | 142K | **2.4M** | 2.0M | 377K | **17x** |
|
|
518
|
+
| event log (combined) | 381K | 600K | **5.6M** | — | — | 9.3x |
|
|
519
|
+
| object with transform (zero-capture) | 1.2M | 1.9M | **6.2M** | — | — | 3.3x |
|
|
520
|
+
| array 10 × transform (zero-capture) | 110K | 217K | **3.1M** | — | — | **14x** |
|
|
521
|
+
| array 50 × transform (zero-capture) | 25K | 44K | **822K** | — | — | **19x** |
|
|
522
|
+
| object with captured transform (partial fallback) | 1.4M | 6.3M | **6.4M** | — | — | 1.0x |
|
|
523
|
+
|
|
524
|
+
_ops/s, higher is better. "—" = not supported by the library. Measured with `vitest bench` on Apple M4 Max (zod 4.3.6, zod v3 3.23.8, typia 12, ajv 8)._
|
|
525
|
+
|
|
526
|
+
Performance scales with schema complexity. Nested objects and arrays see the biggest gains because zod-compiler eliminates per-node traversal overhead. `discriminatedUnion` uses O(1) `switch` dispatch instead of Zod's sequential trial. The invalid-input row is large because failed `safeParse` defers error materialization until `.error` is read. Zero-capture `transform`/`refine` callbacks are compiled (3-19x); schemas with captured callbacks fall back per-field and roughly match Zod.
|
|
527
|
+
|
|
528
|
+
`parse()` (throwing API) rides a zero-allocation fast path: medium object 2.2M → 9.7M ops/s (4.4x), large object (100 items) 18K → 1.4M ops/s (77x).
|
|
524
529
|
|
|
525
530
|
```bash
|
|
526
531
|
pnpm benchmark # run locally
|
|
@@ -24,6 +24,16 @@ export declare const ISSUE_DECLS: Readonly<Record<string, string>>;
|
|
|
24
24
|
* zod scales both operands to integers by their decimal-place count first.
|
|
25
25
|
*/
|
|
26
26
|
export declare const ZC_FSR_DECL = "function __zcFsr(v,s){var vd=((\"\"+v).split(\".\")[1]||\"\").length;var ss=\"\"+s;var sd=(ss.split(\".\")[1]||\"\").length;if(sd===0&&/\\d?e-\\d?/.test(ss)){var m=ss.match(/\\d?e-(\\d?)/);if(m&&m[1]){sd=parseInt(m[1],10);}}var d=vd>sd?vd:sd;var vi=parseInt(v.toFixed(d).replace(\".\",\"\"),10);var si=parseInt(s.toFixed(d).replace(\".\",\"\"),10);return (vi%si)/Math.pow(10,d);}";
|
|
27
|
+
/**
|
|
28
|
+
* Hoisted `Object.prototype.hasOwnProperty` reference. Record fast/slow paths
|
|
29
|
+
* iterate keys with `for(k in o)` (no `Object.keys` array allocation) and guard
|
|
30
|
+
* each key with `__zcHop.call(o,k)` to skip inherited enumerable properties —
|
|
31
|
+
* yielding the exact own-enumerable string-key set `Object.keys` would, so
|
|
32
|
+
* fast/slow stay in agreement and parity with zod's own-key record semantics is
|
|
33
|
+
* preserved. The hoisted reference inlines in V8; reading the prototype property
|
|
34
|
+
* per call would not.
|
|
35
|
+
*/
|
|
36
|
+
export declare const ZC_HOP_DECL = "const __zcHop=Object.prototype.hasOwnProperty;";
|
|
27
37
|
/** Non-issue runtime helper declarations hosted in the virtual module. */
|
|
28
38
|
export declare const RUNTIME_HELPER_DECLS: Readonly<Record<string, string>>;
|
|
29
39
|
//# sourceMappingURL=issue-decls.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"issue-decls.d.ts","sourceRoot":"","sources":["../../../src/core/codegen/issue-decls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA0BH,6DAA6D;AAC7D,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CASxD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,gYACmV,CAAC;AAE5W,0EAA0E;AAC1E,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"issue-decls.d.ts","sourceRoot":"","sources":["../../../src/core/codegen/issue-decls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA0BH,6DAA6D;AAC7D,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CASxD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,gYACmV,CAAC;AAE5W;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,mDAAmD,CAAC;AAE5E,0EAA0E;AAC1E,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAGjE,CAAC"}
|
|
@@ -41,8 +41,19 @@ export const ISSUE_DECLS = {
|
|
|
41
41
|
* zod scales both operands to integers by their decimal-place count first.
|
|
42
42
|
*/
|
|
43
43
|
export const ZC_FSR_DECL = 'function __zcFsr(v,s){var vd=((""+v).split(".")[1]||"").length;var ss=""+s;var sd=(ss.split(".")[1]||"").length;if(sd===0&&/\\d?e-\\d?/.test(ss)){var m=ss.match(/\\d?e-(\\d?)/);if(m&&m[1]){sd=parseInt(m[1],10);}}var d=vd>sd?vd:sd;var vi=parseInt(v.toFixed(d).replace(".",""),10);var si=parseInt(s.toFixed(d).replace(".",""),10);return (vi%si)/Math.pow(10,d);}';
|
|
44
|
+
/**
|
|
45
|
+
* Hoisted `Object.prototype.hasOwnProperty` reference. Record fast/slow paths
|
|
46
|
+
* iterate keys with `for(k in o)` (no `Object.keys` array allocation) and guard
|
|
47
|
+
* each key with `__zcHop.call(o,k)` to skip inherited enumerable properties —
|
|
48
|
+
* yielding the exact own-enumerable string-key set `Object.keys` would, so
|
|
49
|
+
* fast/slow stay in agreement and parity with zod's own-key record semantics is
|
|
50
|
+
* preserved. The hoisted reference inlines in V8; reading the prototype property
|
|
51
|
+
* per call would not.
|
|
52
|
+
*/
|
|
53
|
+
export const ZC_HOP_DECL = "const __zcHop=Object.prototype.hasOwnProperty;";
|
|
44
54
|
/** Non-issue runtime helper declarations hosted in the virtual module. */
|
|
45
55
|
export const RUNTIME_HELPER_DECLS = {
|
|
46
56
|
__zcFsr: ZC_FSR_DECL,
|
|
57
|
+
__zcHop: ZC_HOP_DECL,
|
|
47
58
|
};
|
|
48
59
|
//# sourceMappingURL=issue-decls.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"issue-decls.js","sourceRoot":"","sources":["../../../src/core/codegen/issue-decls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,UAAU,GACd,uJAAuJ,CAAC;AAE1J,MAAM,gBAAgB,GACpB,oKAAoK,CAAC;AAEvK,MAAM,UAAU,GACd,qJAAqJ,CAAC;AAExJ,MAAM,gBAAgB,GACpB,kKAAkK,CAAC;AAErK,MAAM,UAAU,GACd,kIAAkI,CAAC;AAErI,MAAM,UAAU,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IG;AACH,MAAM,CAAC,MAAM,WAAW,GACtB,yWAAyW,CAAC;AAE5W;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,gDAAgD,CAAC;AAE5E,0EAA0E;AAC1E,MAAM,CAAC,MAAM,oBAAoB,GAAqC;IACpE,OAAO,EAAE,WAAW;IACpB,OAAO,EAAE,WAAW;CACrB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../../../src/core/codegen/schemas/record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../../../src/core/codegen/schemas/record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAMtD,wBAAgB,UAAU,CAAC,EAAE,EAAE,QAAQ,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,EAAE,CAAC,EAAE,OAAO,GAAG,MAAM,CAoChF;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAuClE"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { extendPath, hasMutation } from "../context.js";
|
|
1
|
+
import { emitRuntimeHelper, extendPath, hasMutation } from "../context.js";
|
|
2
2
|
import { emit } from "../emit.js";
|
|
3
3
|
import { invalidType } from "../emit-issue.js";
|
|
4
|
+
import { ZC_HOP_DECL } from "../issue-decls.js";
|
|
4
5
|
export function slowRecord(ir, g) {
|
|
5
6
|
let code = emit `
|
|
6
7
|
if(typeof ${g.input}!=="object"||${g.input}===null||Array.isArray(${g.input})){
|
|
@@ -9,16 +10,21 @@ export function slowRecord(ir, g) {
|
|
|
9
10
|
if (hasMutation(ir.valueType)) {
|
|
10
11
|
code += `${g.output}={...${g.input}};`;
|
|
11
12
|
}
|
|
12
|
-
const keysVar = g.temp("rk");
|
|
13
|
-
const idxVar = g.temp("ri");
|
|
14
13
|
const keyVar = g.temp("rkey");
|
|
15
14
|
const keyIssuesVar = g.temp("rki");
|
|
16
15
|
const keyPath = extendPath(g.path, keyVar);
|
|
17
16
|
const valExpr = `${g.input}[${keyVar}]`;
|
|
17
|
+
// for-in + hasOwnProperty guard instead of Object.keys(): identical
|
|
18
|
+
// own-enumerable string-key set and iteration order, no keys-array
|
|
19
|
+
// allocation. When the value type mutates (coerce/default/.trim()) the clone
|
|
20
|
+
// above has already replaced g.input, so this iterates the clone exactly as
|
|
21
|
+
// the Object.keys form did — the key set is stable (values change, keys
|
|
22
|
+
// don't). Records whose values mutate run this path eagerly, so they get the
|
|
23
|
+
// same speedup the fast path does.
|
|
24
|
+
const hop = emitRuntimeHelper(g.ctx, "__zcHop", ZC_HOP_DECL);
|
|
18
25
|
code += emit `
|
|
19
|
-
var ${
|
|
20
|
-
|
|
21
|
-
var ${keyVar}=${keysVar}[${idxVar}];
|
|
26
|
+
for(var ${keyVar} in ${g.input}){
|
|
27
|
+
if(!${hop}.call(${g.input},${keyVar}))continue;
|
|
22
28
|
var ${keyIssuesVar}=[];
|
|
23
29
|
${g.visit(ir.keyType, { input: keyVar, output: keyVar, path: keyPath, issues: keyIssuesVar })}
|
|
24
30
|
if(${keyIssuesVar}.length>0){
|
|
@@ -53,7 +59,14 @@ export function fastRecord(ir, g) {
|
|
|
53
59
|
if (conditions.length > 0) {
|
|
54
60
|
const helperName = g.temp("rf");
|
|
55
61
|
const valAssign = valCheck !== "true" ? `${vv}=o[${kv}];` : "";
|
|
56
|
-
|
|
62
|
+
// for-in (no Object.keys array allocation) + hasOwnProperty guard. The
|
|
63
|
+
// guard restricts iteration to own enumerable string keys — the exact set
|
|
64
|
+
// Object.keys/the slow path produce — so inherited enumerable props can't
|
|
65
|
+
// make the fast check disagree with the deferred slow walk. Measured 2.9x
|
|
66
|
+
// (5 keys) to 5.8x (20 keys) faster than the Object.keys form; the hoisted
|
|
67
|
+
// __zcHop.call inlines, making the guard ~free vs an unguarded for-in.
|
|
68
|
+
const hop = emitRuntimeHelper(g.ctx, "__zcHop", ZC_HOP_DECL);
|
|
69
|
+
g.ctx.preamble.push(`function ${helperName}(o){var ${kv},${vv};for(${kv} in o){if(${hop}.call(o,${kv})){${valAssign}if(!(${conditions.join("&&")})){return false;}}}return true;}`);
|
|
57
70
|
parts.push(`${helperName}(${x})`);
|
|
58
71
|
}
|
|
59
72
|
return parts.join("&&");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.js","sourceRoot":"","sources":["../../../../src/core/codegen/schemas/record.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["../../../../src/core/codegen/schemas/record.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,UAAU,UAAU,CAAC,EAAiC,EAAE,CAAU;IACtE,IAAI,IAAI,GAAG,IAAI,CAAA;gBACD,CAAC,CAAC,KAAK,gBAAgB,CAAC,CAAC,KAAK,0BAA0B,CAAC,CAAC,KAAK;QACvE,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC;WACrB,CAAC;IAEV,IAAI,WAAW,CAAC,EAAE,CAA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