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 = code_1.schemaProperties(it, schema);
15 // TODO mark properties matching patterns with always valid schemas as evaluated
16 if (patterns.length === 0)
18 const checkProperties = opts.strictSchema && !opts.allowMatchingProperties && parentSchema.properties;
19 const valid = gen.name("valid");
20 if (it.props !== true && !(it.props instanceof codegen_1.Name)) {
21 it.props = util_2.evaluatedPropsToName(gen, it.props);
24 validatePatternProperties();
25 function validatePatternProperties() {
26 for (const pat of patterns) {
28 checkMatchingProperties(pat);
30 validateProperties(pat);
33 gen.var(valid, true); // TODO var
34 validateProperties(pat);
39 function checkMatchingProperties(pat) {
40 for (const prop in checkProperties) {
41 if (new RegExp(pat).test(prop)) {
42 util_1.checkStrictMode(it, `property ${prop} matches pattern ${pat} (use allowMatchingProperties)`);
46 function validateProperties(pat) {
47 gen.forIn("key", data, (key) => {
48 gen.if(codegen_1._ `${code_1.usePattern(gen, pat)}.test(${key})`, () => {
50 keyword: "patternProperties",
53 dataPropType: util_2.Type.Str,
55 if (it.opts.unevaluated && props !== true) {
56 gen.assign(codegen_1._ `${props}[${key}]`, true);
58 else if (!it.allErrors) {
59 // can short-circuit if `unevaluatedProperties` is not supported (opts.next === false)
60 // or if all properties were evaluated (props === true)
61 gen.if(codegen_1.not(valid), () => gen.break());
68 exports.default = def;
69 //# sourceMappingURL=patternProperties.js.map