source: trip-planner-front/node_modules/ajv/dist/vocabularies/applicator/if.js@ 84d0fbb

Last change on this file since 84d0fbb was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.4 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const codegen_1 = require("../../compile/codegen");
4const util_1 = require("../../compile/util");
5const error = {
6 message: ({ params }) => codegen_1.str `must match "${params.ifClause}" schema`,
7 params: ({ params }) => codegen_1._ `{failingKeyword: ${params.ifClause}}`,
8};
9const def = {
10 keyword: "if",
11 schemaType: ["object", "boolean"],
12 trackErrors: true,
13 error,
14 code(cxt) {
15 const { gen, parentSchema, it } = cxt;
16 if (parentSchema.then === undefined && parentSchema.else === undefined) {
17 util_1.checkStrictMode(it, '"if" without "then" and "else" is ignored');
18 }
19 const hasThen = hasSchema(it, "then");
20 const hasElse = hasSchema(it, "else");
21 if (!hasThen && !hasElse)
22 return;
23 const valid = gen.let("valid", true);
24 const schValid = gen.name("_valid");
25 validateIf();
26 cxt.reset();
27 if (hasThen && hasElse) {
28 const ifClause = gen.let("ifClause");
29 cxt.setParams({ ifClause });
30 gen.if(schValid, validateClause("then", ifClause), validateClause("else", ifClause));
31 }
32 else if (hasThen) {
33 gen.if(schValid, validateClause("then"));
34 }
35 else {
36 gen.if(codegen_1.not(schValid), validateClause("else"));
37 }
38 cxt.pass(valid, () => cxt.error(true));
39 function validateIf() {
40 const schCxt = cxt.subschema({
41 keyword: "if",
42 compositeRule: true,
43 createErrors: false,
44 allErrors: false,
45 }, schValid);
46 cxt.mergeEvaluated(schCxt);
47 }
48 function validateClause(keyword, ifClause) {
49 return () => {
50 const schCxt = cxt.subschema({ keyword }, schValid);
51 gen.assign(valid, schValid);
52 cxt.mergeValidEvaluated(schCxt, valid);
53 if (ifClause)
54 gen.assign(ifClause, codegen_1._ `${keyword}`);
55 else
56 cxt.setParams({ ifClause: keyword });
57 };
58 }
59 },
60};
61function hasSchema(it, keyword) {
62 const schema = it.schema[keyword];
63 return schema !== undefined && !util_1.alwaysValidSchema(it, schema);
64}
65exports.default = def;
66//# sourceMappingURL=if.js.map
Note: See TracBrowser for help on using the repository browser.