optimized required rule compilation
parent
dfd6de5857
commit
286368fb23
|
@ -53,7 +53,7 @@
|
|||
it.errorPath = ($currentErrorPath + ' + \'' + $missingProperty + '\'').replace('" + "', '');
|
||||
}}
|
||||
if ({{=$data}}{{=$prop}} === undefined) {
|
||||
{{# def.error:'required' }}
|
||||
{{# def.addError:'required' }}
|
||||
}
|
||||
{{~}}
|
||||
{{??}}
|
||||
|
@ -61,7 +61,7 @@
|
|||
|
||||
for (var {{=$i}} = 0; {{=$i}} < schema{{=$lvl}}.length; {{=$i}}++) {
|
||||
if ({{=$data}}[schema{{=$lvl}}[{{=$i}}]] === undefined) {
|
||||
{{# def.error:'required' }}
|
||||
{{# def.addError:'required' }}
|
||||
}
|
||||
}
|
||||
{{?}}
|
||||
|
|
|
@ -78,21 +78,11 @@ module.exports = function anonymous(it) {
|
|||
var $prop = it.util.getProperty($property),
|
||||
$missingProperty = it.util.escapeQuotes($prop);
|
||||
it.errorPath = ($currentErrorPath + ' + \'' + $missingProperty + '\'').replace('" + "', '');
|
||||
out += ' if (' + ($data) + ($prop) + ' === undefined) { ';
|
||||
if (it.wasTop && $breakOnError) {
|
||||
out += ' validate.errors = [ { keyword: \'' + ('required') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'property ' + ($missingProperty) + ' is required\' ';
|
||||
if (it.opts.verbose) {
|
||||
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
|
||||
}
|
||||
out += ' }]; return false; ';
|
||||
} else {
|
||||
out += ' var err = { keyword: \'' + ('required') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'property ' + ($missingProperty) + ' is required\' ';
|
||||
if (it.opts.verbose) {
|
||||
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
|
||||
}
|
||||
out += ' }; if (validate.errors === null) validate.errors = [err]; else validate.errors.push(err); errors++; ';
|
||||
out += ' if (' + ($data) + ($prop) + ' === undefined) { var err = { keyword: \'' + ('required') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'property ' + ($missingProperty) + ' is required\' ';
|
||||
if (it.opts.verbose) {
|
||||
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
|
||||
}
|
||||
out += ' } ';
|
||||
out += ' }; if (validate.errors === null) validate.errors = [err]; else validate.errors.push(err); errors++; } ';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -101,21 +91,11 @@ module.exports = function anonymous(it) {
|
|||
$propertyPath = ' + schema' + $lvl + '[' + $i + '] + ',
|
||||
$missingProperty = '\' + "\'"' + $propertyPath + '"\'" + \'';
|
||||
it.errorPath = ($currentErrorPath + ' + "[\'"' + $propertyPath + '"\']"').replace('" + "', '');
|
||||
out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < schema' + ($lvl) + '.length; ' + ($i) + '++) { if (' + ($data) + '[schema' + ($lvl) + '[' + ($i) + ']] === undefined) { ';
|
||||
if (it.wasTop && $breakOnError) {
|
||||
out += ' validate.errors = [ { keyword: \'' + ('required') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'property ' + ($missingProperty) + ' is required\' ';
|
||||
if (it.opts.verbose) {
|
||||
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
|
||||
}
|
||||
out += ' }]; return false; ';
|
||||
} else {
|
||||
out += ' var err = { keyword: \'' + ('required') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'property ' + ($missingProperty) + ' is required\' ';
|
||||
if (it.opts.verbose) {
|
||||
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
|
||||
}
|
||||
out += ' }; if (validate.errors === null) validate.errors = [err]; else validate.errors.push(err); errors++; ';
|
||||
out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < schema' + ($lvl) + '.length; ' + ($i) + '++) { if (' + ($data) + '[schema' + ($lvl) + '[' + ($i) + ']] === undefined) { var err = { keyword: \'' + ('required') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'property ' + ($missingProperty) + ' is required\' ';
|
||||
if (it.opts.verbose) {
|
||||
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data);
|
||||
}
|
||||
out += ' } } ';
|
||||
out += ' }; if (validate.errors === null) validate.errors = [err]; else validate.errors.push(err); errors++; } } ';
|
||||
}
|
||||
}
|
||||
it.errorPath = $currentErrorPath;
|
||||
|
|
Loading…
Reference in New Issue