source: trip-planner-front/node_modules/ajv/dist/vocabularies/dynamic/dynamicRef.js

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

initial commit

  • Property mode set to 100644
File size: 1.9 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.dynamicRef = void 0;
4const codegen_1 = require("../../compile/codegen");
5const names_1 = require("../../compile/names");
6const ref_1 = require("../core/ref");
7const def = {
8 keyword: "$dynamicRef",
9 schemaType: "string",
10 code: (cxt) => dynamicRef(cxt, cxt.schema),
11};
12function dynamicRef(cxt, ref) {
13 const { gen, keyword, it } = cxt;
14 if (ref[0] !== "#")
15 throw new Error(`"${keyword}" only supports hash fragment reference`);
16 const anchor = ref.slice(1);
17 if (it.allErrors) {
18 _dynamicRef();
19 }
20 else {
21 const valid = gen.let("valid", false);
22 _dynamicRef(valid);
23 cxt.ok(valid);
24 }
25 function _dynamicRef(valid) {
26 // TODO the assumption here is that `recursiveRef: #` always points to the root
27 // of the schema object, which is not correct, because there may be $id that
28 // makes # point to it, and the target schema may not contain dynamic/recursiveAnchor.
29 // Because of that 2 tests in recursiveRef.json fail.
30 // This is a similar problem to #815 (`$id` doesn't alter resolution scope for `{ "$ref": "#" }`).
31 // (This problem is not tested in JSON-Schema-Test-Suite)
32 if (it.schemaEnv.root.dynamicAnchors[anchor]) {
33 const v = gen.let("_v", codegen_1._ `${names_1.default.dynamicAnchors}${codegen_1.getProperty(anchor)}`);
34 gen.if(v, _callRef(v, valid), _callRef(it.validateName, valid));
35 }
36 else {
37 _callRef(it.validateName, valid)();
38 }
39 }
40 function _callRef(validate, valid) {
41 return valid
42 ? () => gen.block(() => {
43 ref_1.callRef(cxt, validate);
44 gen.let(valid, true);
45 })
46 : () => ref_1.callRef(cxt, validate);
47 }
48}
49exports.dynamicRef = dynamicRef;
50exports.default = def;
51//# sourceMappingURL=dynamicRef.js.map
Note: See TracBrowser for help on using the repository browser.