[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.default = validate;
|
---|
| 7 | exports.validateField = validateField;
|
---|
| 8 | exports.validateChild = validateChild;
|
---|
| 9 |
|
---|
| 10 | var _definitions = require("../definitions");
|
---|
| 11 |
|
---|
| 12 | function validate(node, key, val) {
|
---|
| 13 | if (!node) return;
|
---|
| 14 | const fields = _definitions.NODE_FIELDS[node.type];
|
---|
| 15 | if (!fields) return;
|
---|
| 16 | const field = fields[key];
|
---|
| 17 | validateField(node, key, val, field);
|
---|
| 18 | validateChild(node, key, val);
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | function validateField(node, key, val, field) {
|
---|
| 22 | if (!(field != null && field.validate)) return;
|
---|
| 23 | if (field.optional && val == null) return;
|
---|
| 24 | field.validate(node, key, val);
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | function validateChild(node, key, val) {
|
---|
| 28 | if (val == null) return;
|
---|
| 29 | const validate = _definitions.NODE_PARENT_VALIDATIONS[val.type];
|
---|
| 30 | if (!validate) return;
|
---|
| 31 | validate(node, key, val);
|
---|
| 32 | } |
---|