1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.dynamicRef = void 0;
|
4 | const codegen_1 = require("../../compile/codegen");
|
5 | const names_1 = require("../../compile/names");
|
6 | const ref_1 = require("../core/ref");
|
7 | const def = {
|
8 | keyword: "$dynamicRef",
|
9 | schemaType: "string",
|
10 | code: (cxt) => dynamicRef(cxt, cxt.schema),
|
11 | };
|
12 | function 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 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | if (it.schemaEnv.root.dynamicAnchors[anchor]) {
|
33 | const v = gen.let("_v", (0, codegen_1._) `${names_1.default.dynamicAnchors}${(0, 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 | (0, ref_1.callRef)(cxt, validate);
|
44 | gen.let(valid, true);
|
45 | })
|
46 | : () => (0, ref_1.callRef)(cxt, validate);
|
47 | }
|
48 | }
|
49 | exports.dynamicRef = dynamicRef;
|
50 | exports.default = def;
|
51 |
|
\ | No newline at end of file |