removed unused it.dataPath, related to #32

master
Evgeny Poberezkin 2015-08-19 00:31:03 +01:00
parent e74f79eea6
commit cfec9e3fb3
8 changed files with 21 additions and 20 deletions

View File

@ -37,7 +37,6 @@ function compile(schema, root, localRefs) {
root: _root,
schemaPath: '',
errorPath: '""',
dataPath: '',
RULES: RULES,
validate: validateGenerator,
util: util,

View File

@ -7,7 +7,6 @@
for (var i{{=$lvl}} = {{=startFrom}}; i{{=$lvl}} < {{=$data}}.length; i{{=$lvl}}++) {
{{
$it.errorPath = (it.errorPath + ' + "[" + i' + $lvl + ' + "]"').replace('" + "', '');
$it.dataPath = it.dataPath + '[i' + $lvl + ']';
var $passData = $data + '[i' + $lvl + ']';
}}
@ -46,7 +45,6 @@ var {{=$valid}};
$it.schema = $sch;
$it.schemaPath = $schemaPath + '[' + $i + ']';
$it.errorPath = (it.errorPath + ' + "[' + $i + ']"').replace('" + "', '');
$it.dataPath = it.dataPath + '[' + $i + ']';
var $passData = $data + '[' + $i + ']';
}}

View File

@ -63,7 +63,6 @@ var valid{{=$it.level}} = true;
$it.schema = $aProperties;
$it.schemaPath = it.schemaPath + '.additionalProperties';
$it.errorPath = it.errorPath;
$it.dataPath = it.dataPath + '[key' + $lvl + ']';
var $passData = $data + '[key' + $lvl + ']';
}}
@ -102,7 +101,6 @@ var valid{{=$it.level}} = true;
, $passData = $data + $prop;
$it.schemaPath = $schemaPath + $prop;
$it.errorPath = (it.errorPath + ' + "' + $prop + '"').replace('" + "', '');
$it.dataPath = it.dataPath + $prop;
}}
{{ var $code = it.validate($it); }}
@ -145,7 +143,6 @@ var valid{{=$it.level}} = true;
if (/{{= it.util.escapeRegExp($pProperty) }}/.test(key{{=$lvl}})) {
{{
$it.errorPath = (it.errorPath + ' + "[\'" + key' + $lvl + ' + "\']"').replace('" + "', '');
$it.dataPath = it.dataPath + '[key' + $lvl + ']';
var $passData = $data + '[key' + $lvl + ']';
}}

View File

@ -9,7 +9,7 @@
} {{? $breakOnError }} else { {{?}}
#}}
{{## def._validateRef:_v: {{=_v}}({{=$data}}, (dataPath || '') + {{= it.errorPath }}) #}}
{{## def._validateRef:_v: {{=_v}}({{=$data}}, (dataPath || ''){{? it.errorPath != '""'}} + {{= it.errorPath }}{{?}}) #}}
{{? $schema == '#' || $schema == '#/' }}
{{? it.isRoot }}

View File

@ -49,7 +49,6 @@ module.exports = function anonymous(it) {
$it.schema = $sch;
$it.schemaPath = $schemaPath + '[' + $i + ']';
$it.errorPath = (it.errorPath + ' + "[' + $i + ']"').replace('" + "', '');
$it.dataPath = it.dataPath + '[' + $i + ']';
var $passData = $data + '[' + $i + ']';
var $code = it.validate($it);
if (it.util.varOccurences($code, $nextData) < 2) {
@ -70,7 +69,6 @@ module.exports = function anonymous(it) {
$it.schemaPath = it.schemaPath + '.additionalItems';
out += ' valid' + ($it.level) + ' = true; if (' + ($data) + '.length > ' + ($schema.length) + ') { for (var i' + ($lvl) + ' = ' + ($schema.length) + '; i' + ($lvl) + ' < ' + ($data) + '.length; i' + ($lvl) + '++) { ';
$it.errorPath = (it.errorPath + ' + "[" + i' + $lvl + ' + "]"').replace('" + "', '');
$it.dataPath = it.dataPath + '[i' + $lvl + ']';
var $passData = $data + '[i' + $lvl + ']';
var $code = it.validate($it);
if (it.util.varOccurences($code, $nextData) < 2) {
@ -92,7 +90,6 @@ module.exports = function anonymous(it) {
$it.schemaPath = $schemaPath;
out += ' for (var i' + ($lvl) + ' = ' + (0) + '; i' + ($lvl) + ' < ' + ($data) + '.length; i' + ($lvl) + '++) { ';
$it.errorPath = (it.errorPath + ' + "[" + i' + $lvl + ' + "]"').replace('" + "', '');
$it.dataPath = it.dataPath + '[i' + $lvl + ']';
var $passData = $data + '[i' + $lvl + ']';
var $code = it.validate($it);
if (it.util.varOccurences($code, $nextData) < 2) {

View File

@ -75,7 +75,6 @@ module.exports = function anonymous(it) {
$it.schema = $aProperties;
$it.schemaPath = it.schemaPath + '.additionalProperties';
$it.errorPath = it.errorPath;
$it.dataPath = it.dataPath + '[key' + $lvl + ']';
var $passData = $data + '[key' + $lvl + ']';
var $code = it.validate($it);
if (it.util.varOccurences($code, $nextData) < 2) {
@ -108,7 +107,6 @@ module.exports = function anonymous(it) {
$passData = $data + $prop;
$it.schemaPath = $schemaPath + $prop;
$it.errorPath = (it.errorPath + ' + "' + $prop + '"').replace('" + "', '');
$it.dataPath = it.dataPath + $prop;
var $code = it.validate($it);
if (it.util.varOccurences($code, $nextData) < 2) {
$code = it.util.varReplace($code, $nextData, $passData);
@ -142,7 +140,6 @@ module.exports = function anonymous(it) {
$it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
out += ' for (var key' + ($lvl) + ' in ' + ($data) + ') { if (/' + (it.util.escapeRegExp($pProperty)) + '/.test(key' + ($lvl) + ')) { ';
$it.errorPath = (it.errorPath + ' + "[\'" + key' + $lvl + ' + "\']"').replace('" + "', '');
$it.dataPath = it.dataPath + '[key' + $lvl + ']';
var $passData = $data + '[key' + $lvl + ']';
var $code = it.validate($it);
if (it.util.varOccurences($code, $nextData) < 2) {

View File

@ -12,15 +12,27 @@ module.exports = function anonymous(it) {
if ($schema == '#' || $schema == '#/') {
if (it.isRoot) {
if ($breakOnError && it.wasTop) {
out += ' if (! ' + ('validate') + '(' + ($data) + ', (dataPath || \'\') + ' + (it.errorPath) + ') ) return false; else { ';
out += ' if (! ' + ('validate') + '(' + ($data) + ', (dataPath || \'\')';
if (it.errorPath != '""') {
out += ' + ' + (it.errorPath);
}
out += ') ) return false; else { ';
} else {
out += ' if (! ' + ('validate') + '(' + ($data) + ', (dataPath || \'\') + ' + (it.errorPath) + ') ) { if (vErrors === null) vErrors = ' + ('validate') + '.errors; else vErrors = vErrors.concat(' + ('validate') + '.errors); errors = vErrors.length; } ';
out += ' if (! ' + ('validate') + '(' + ($data) + ', (dataPath || \'\')';
if (it.errorPath != '""') {
out += ' + ' + (it.errorPath);
}
out += ') ) { if (vErrors === null) vErrors = ' + ('validate') + '.errors; else vErrors = vErrors.concat(' + ('validate') + '.errors); errors = vErrors.length; } ';
if ($breakOnError) {
out += ' else { ';
}
}
} else {
out += ' if (! ' + ('root.refVal[0]') + '(' + ($data) + ', (dataPath || \'\') + ' + (it.errorPath) + ') ) { if (vErrors === null) vErrors = ' + ('root.refVal[0]') + '.errors; else vErrors = vErrors.concat(' + ('root.refVal[0]') + '.errors); errors = vErrors.length; } ';
out += ' if (! ' + ('root.refVal[0]') + '(' + ($data) + ', (dataPath || \'\')';
if (it.errorPath != '""') {
out += ' + ' + (it.errorPath);
}
out += ') ) { if (vErrors === null) vErrors = ' + ('root.refVal[0]') + '.errors; else vErrors = vErrors.concat(' + ('root.refVal[0]') + '.errors); errors = vErrors.length; } ';
if ($breakOnError) {
out += ' else { ';
}
@ -56,7 +68,11 @@ module.exports = function anonymous(it) {
throw new Error($message);
}
} else {
out += ' if (! ' + ($refVal) + '(' + ($data) + ', (dataPath || \'\') + ' + (it.errorPath) + ') ) { if (vErrors === null) vErrors = ' + ($refVal) + '.errors; else vErrors = vErrors.concat(' + ($refVal) + '.errors); errors = vErrors.length; } ';
out += ' if (! ' + ($refVal) + '(' + ($data) + ', (dataPath || \'\')';
if (it.errorPath != '""') {
out += ' + ' + (it.errorPath);
}
out += ') ) { if (vErrors === null) vErrors = ' + ($refVal) + '.errors; else vErrors = vErrors.concat(' + ($refVal) + '.errors); errors = vErrors.length; } ';
if ($breakOnError) {
out += ' else { ';
}

View File

@ -12,9 +12,6 @@ module.exports = function anonymous(it) {
out += ' validate = function (data, dataPath) { \'use strict\'; var vErrors = null; ';
out += ' var errors = 0; ';
} else {
if (it.opts._debug) {
out += ' console.log(\'validate dataPath:\', dataPath); ';
}
var $lvl = it.level,
$dataLvl = it.dataLevel,
$data = 'data' + ($dataLvl || '');