.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / table / node_modules / ajv / dist / vocabularies / applicator / patternProperties.js
1 "use strict";
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");
7 const def = {
8     keyword: "patternProperties",
9     type: "object",
10     schemaType: "object",
11     code(cxt) {
12         const { gen, schema, data, parentSchema, it } = cxt;
13         const { opts } = it;
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)
17             return;
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);
22         }
23         const { props } = it;
24         validatePatternProperties();
25         function validatePatternProperties() {
26             for (const pat of patterns) {
27                 if (checkProperties)
28                     checkMatchingProperties(pat);
29                 if (it.allErrors) {
30                     validateProperties(pat);
31                 }
32                 else {
33                     gen.var(valid, true); // TODO var
34                     validateProperties(pat);
35                     gen.if(valid);
36                 }
37             }
38         }
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)`);
43                 }
44             }
45         }
46         function validateProperties(pat) {
47             gen.forIn("key", data, (key) => {
48                 gen.if(codegen_1._ `${code_1.usePattern(gen, pat)}.test(${key})`, () => {
49                     cxt.subschema({
50                         keyword: "patternProperties",
51                         schemaProp: pat,
52                         dataProp: key,
53                         dataPropType: util_2.Type.Str,
54                     }, valid);
55                     if (it.opts.unevaluated && props !== true) {
56                         gen.assign(codegen_1._ `${props}[${key}]`, true);
57                     }
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());
62                     }
63                 });
64             });
65         }
66     },
67 };
68 exports.default = def;
69 //# sourceMappingURL=patternProperties.js.map