.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / table / node_modules / ajv / dist / vocabularies / code.js
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.validateUnion = exports.validateArray = exports.usePattern = exports.callValidateCode = exports.schemaProperties = exports.allSchemaProperties = exports.noPropertyInData = exports.propertyInData = exports.isOwnProperty = exports.hasPropFunc = exports.reportMissingProp = exports.checkMissingProp = exports.checkReportMissingProp = void 0;
4 const codegen_1 = require("../compile/codegen");
5 const util_1 = require("../compile/util");
6 const names_1 = require("../compile/names");
7 function checkReportMissingProp(cxt, prop) {
8     const { gen, data, it } = cxt;
9     gen.if(noPropertyInData(gen, data, prop, it.opts.ownProperties), () => {
10         cxt.setParams({ missingProperty: codegen_1._ `${prop}` }, true);
11         cxt.error();
12     });
13 }
14 exports.checkReportMissingProp = checkReportMissingProp;
15 function checkMissingProp({ gen, data, it: { opts } }, properties, missing) {
16     return codegen_1.or(...properties.map((prop) => codegen_1.and(noPropertyInData(gen, data, prop, opts.ownProperties), codegen_1._ `${missing} = ${prop}`)));
17 }
18 exports.checkMissingProp = checkMissingProp;
19 function reportMissingProp(cxt, missing) {
20     cxt.setParams({ missingProperty: missing }, true);
21     cxt.error();
22 }
23 exports.reportMissingProp = reportMissingProp;
24 function hasPropFunc(gen) {
25     return gen.scopeValue("func", {
26         // eslint-disable-next-line @typescript-eslint/unbound-method
27         ref: Object.prototype.hasOwnProperty,
28         code: codegen_1._ `Object.prototype.hasOwnProperty`,
29     });
30 }
31 exports.hasPropFunc = hasPropFunc;
32 function isOwnProperty(gen, data, property) {
33     return codegen_1._ `${hasPropFunc(gen)}.call(${data}, ${property})`;
34 }
35 exports.isOwnProperty = isOwnProperty;
36 function propertyInData(gen, data, property, ownProperties) {
37     const cond = codegen_1._ `${data}${codegen_1.getProperty(property)} !== undefined`;
38     return ownProperties ? codegen_1._ `${cond} && ${isOwnProperty(gen, data, property)}` : cond;
39 }
40 exports.propertyInData = propertyInData;
41 function noPropertyInData(gen, data, property, ownProperties) {
42     const cond = codegen_1._ `${data}${codegen_1.getProperty(property)} === undefined`;
43     return ownProperties ? codegen_1.or(cond, codegen_1.not(isOwnProperty(gen, data, property))) : cond;
44 }
45 exports.noPropertyInData = noPropertyInData;
46 function allSchemaProperties(schemaMap) {
47     return schemaMap ? Object.keys(schemaMap).filter((p) => p !== "__proto__") : [];
48 }
49 exports.allSchemaProperties = allSchemaProperties;
50 function schemaProperties(it, schemaMap) {
51     return allSchemaProperties(schemaMap).filter((p) => !util_1.alwaysValidSchema(it, schemaMap[p]));
52 }
53 exports.schemaProperties = schemaProperties;
54 function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context, passSchema) {
55     const dataAndSchema = passSchema ? codegen_1._ `${schemaCode}, ${data}, ${topSchemaRef}${schemaPath}` : data;
56     const valCxt = [
57         [names_1.default.instancePath, codegen_1.strConcat(names_1.default.instancePath, errorPath)],
58         [names_1.default.parentData, it.parentData],
59         [names_1.default.parentDataProperty, it.parentDataProperty],
60         [names_1.default.rootData, names_1.default.rootData],
61     ];
62     if (it.opts.dynamicRef)
63         valCxt.push([names_1.default.dynamicAnchors, names_1.default.dynamicAnchors]);
64     const args = codegen_1._ `${dataAndSchema}, ${gen.object(...valCxt)}`;
65     return context !== codegen_1.nil ? codegen_1._ `${func}.call(${context}, ${args})` : codegen_1._ `${func}(${args})`;
66 }
67 exports.callValidateCode = callValidateCode;
68 function usePattern(gen, pattern) {
69     return gen.scopeValue("pattern", {
70         key: pattern,
71         ref: new RegExp(pattern, "u"),
72         code: codegen_1._ `new RegExp(${pattern}, "u")`,
73     });
74 }
75 exports.usePattern = usePattern;
76 function validateArray(cxt) {
77     const { gen, data, keyword, it } = cxt;
78     const valid = gen.name("valid");
79     if (it.allErrors) {
80         const validArr = gen.let("valid", true);
81         validateItems(() => gen.assign(validArr, false));
82         return validArr;
83     }
84     gen.var(valid, true);
85     validateItems(() => gen.break());
86     return valid;
87     function validateItems(notValid) {
88         const len = gen.const("len", codegen_1._ `${data}.length`);
89         gen.forRange("i", 0, len, (i) => {
90             cxt.subschema({
91                 keyword,
92                 dataProp: i,
93                 dataPropType: util_1.Type.Num,
94             }, valid);
95             gen.if(codegen_1.not(valid), notValid);
96         });
97     }
98 }
99 exports.validateArray = validateArray;
100 function validateUnion(cxt) {
101     const { gen, schema, keyword, it } = cxt;
102     /* istanbul ignore if */
103     if (!Array.isArray(schema))
104         throw new Error("ajv implementation error");
105     const alwaysValid = schema.some((sch) => util_1.alwaysValidSchema(it, sch));
106     if (alwaysValid && !it.opts.unevaluated)
107         return;
108     const valid = gen.let("valid", false);
109     const schValid = gen.name("_valid");
110     gen.block(() => schema.forEach((_sch, i) => {
111         const schCxt = cxt.subschema({
112             keyword,
113             schemaProp: i,
114             compositeRule: true,
115         }, schValid);
116         gen.assign(valid, codegen_1._ `${valid} || ${schValid}`);
117         const merged = cxt.mergeValidEvaluated(schCxt, schValid);
118         // can short-circuit if `unevaluatedProperties/Items` not supported (opts.unevaluated !== true)
119         // or if all properties and items were evaluated (it.props === true && it.items === true)
120         if (!merged)
121             gen.if(codegen_1.not(valid));
122     }));
123     cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
124 }
125 exports.validateUnion = validateUnion;
126 //# sourceMappingURL=code.js.map