2 Object.defineProperty(exports, "__esModule", { value: true });
3 const codegen_1 = require("../../compile/codegen");
4 const util_1 = require("../../compile/util");
6 message: ({ params }) => (0, codegen_1.str) `must match "${params.ifClause}" schema`,
7 params: ({ params }) => (0, codegen_1._) `{failingKeyword: ${params.ifClause}}`,
11 schemaType: ["object", "boolean"],
15 const { gen, parentSchema, it } = cxt;
16 if (parentSchema.then === undefined && parentSchema.else === undefined) {
17 (0, util_1.checkStrictMode)(it, '"if" without "then" and "else" is ignored');
19 const hasThen = hasSchema(it, "then");
20 const hasElse = hasSchema(it, "else");
21 if (!hasThen && !hasElse)
23 const valid = gen.let("valid", true);
24 const schValid = gen.name("_valid");
27 if (hasThen && hasElse) {
28 const ifClause = gen.let("ifClause");
29 cxt.setParams({ ifClause });
30 gen.if(schValid, validateClause("then", ifClause), validateClause("else", ifClause));
33 gen.if(schValid, validateClause("then"));
36 gen.if((0, codegen_1.not)(schValid), validateClause("else"));
38 cxt.pass(valid, () => cxt.error(true));
39 function validateIf() {
40 const schCxt = cxt.subschema({
46 cxt.mergeEvaluated(schCxt);
48 function validateClause(keyword, ifClause) {
50 const schCxt = cxt.subschema({ keyword }, schValid);
51 gen.assign(valid, schValid);
52 cxt.mergeValidEvaluated(schCxt, valid);
54 gen.assign(ifClause, (0, codegen_1._) `${keyword}`);
56 cxt.setParams({ ifClause: keyword });
61 function hasSchema(it, keyword) {
62 const schema = it.schema[keyword];
63 return schema !== undefined && !(0, util_1.alwaysValidSchema)(it, schema);
65 exports.default = def;
66 //# sourceMappingURL=if.js.map