2 Object.defineProperty(exports, "__esModule", { value: true });
3 const code_1 = require("../code");
4 const codegen_1 = require("../../compile/codegen");
5 const util_1 = require("../../compile/util");
6 const util_2 = require("../../compile/util");
8 keyword: "patternProperties",
12 const { gen, schema, data, parentSchema, it } = cxt;
14 const patterns = (0, code_1.allSchemaProperties)(schema);
15 const alwaysValidPatterns = patterns.filter((p) => (0, util_1.alwaysValidSchema)(it, schema[p]));
16 if (patterns.length === 0 ||
17 (alwaysValidPatterns.length === patterns.length &&
18 (!it.opts.unevaluated || it.props === true))) {
21 const checkProperties = opts.strictSchema && !opts.allowMatchingProperties && parentSchema.properties;
22 const valid = gen.name("valid");
23 if (it.props !== true && !(it.props instanceof codegen_1.Name)) {
24 it.props = (0, util_2.evaluatedPropsToName)(gen, it.props);
27 validatePatternProperties();
28 function validatePatternProperties() {
29 for (const pat of patterns) {
31 checkMatchingProperties(pat);
33 validateProperties(pat);
36 gen.var(valid, true); // TODO var
37 validateProperties(pat);
42 function checkMatchingProperties(pat) {
43 for (const prop in checkProperties) {
44 if (new RegExp(pat).test(prop)) {
45 (0, util_1.checkStrictMode)(it, `property ${prop} matches pattern ${pat} (use allowMatchingProperties)`);
49 function validateProperties(pat) {
50 gen.forIn("key", data, (key) => {
51 gen.if((0, codegen_1._) `${(0, code_1.usePattern)(cxt, pat)}.test(${key})`, () => {
52 const alwaysValid = alwaysValidPatterns.includes(pat);
55 keyword: "patternProperties",
58 dataPropType: util_2.Type.Str,
61 if (it.opts.unevaluated && props !== true) {
62 gen.assign((0, codegen_1._) `${props}[${key}]`, true);
64 else if (!alwaysValid && !it.allErrors) {
65 // can short-circuit if `unevaluatedProperties` is not supported (opts.next === false)
66 // or if all properties were evaluated (props === true)
67 gen.if((0, codegen_1.not)(valid), () => gen.break());
74 exports.default = def;
75 //# sourceMappingURL=patternProperties.js.map