{"ast":null,"code":"'use strict';\n\nmodule.exports = function generate_custom(it, $keyword, $ruleType) {\n var out = ' ';\n var $lvl = it.level;\n var $dataLvl = it.dataLevel;\n var $schema = it.schema[$keyword];\n var $schemaPath = it.schemaPath + it.util.getProperty($keyword);\n var $errSchemaPath = it.errSchemaPath + '/' + $keyword;\n var $breakOnError = !it.opts.allErrors;\n var $errorKeyword;\n var $data = 'data' + ($dataLvl || '');\n var $valid = 'valid' + $lvl;\n var $errs = 'errs__' + $lvl;\n var $isData = it.opts.$data && $schema && $schema.$data,\n $schemaValue;\n\n if ($isData) {\n out += ' var schema' + $lvl + ' = ' + it.util.getData($schema.$data, $dataLvl, it.dataPathArr) + '; ';\n $schemaValue = 'schema' + $lvl;\n } else {\n $schemaValue = $schema;\n }\n\n var $rule = this,\n $definition = 'definition' + $lvl,\n $rDef = $rule.definition,\n $closingBraces = '';\n var $compile, $inline, $macro, $ruleValidate, $validateCode;\n\n if ($isData && $rDef.$data) {\n $validateCode = 'keywordValidate' + $lvl;\n var $validateSchema = $rDef.validateSchema;\n out += ' var ' + $definition + ' = RULES.custom[\\'' + $keyword + '\\'].definition; var ' + $validateCode + ' = ' + $definition + '.validate;';\n } else {\n $ruleValidate = it.useCustomRule($rule, $schema, it.schema, it);\n if (!$ruleValidate) return;\n $schemaValue = 'validate.schema' + $schemaPath;\n $validateCode = $ruleValidate.code;\n $compile = $rDef.compile;\n $inline = $rDef.inline;\n $macro = $rDef.macro;\n }\n\n var $ruleErrs = $validateCode + '.errors',\n $i = 'i' + $lvl,\n $ruleErr = 'ruleErr' + $lvl,\n $asyncKeyword = $rDef.async;\n if ($asyncKeyword && !it.async) throw new Error('async keyword in sync schema');\n\n if (!($inline || $macro)) {\n out += '' + $ruleErrs + ' = null;';\n }\n\n out += 'var ' + $errs + ' = errors;var ' + $valid + ';';\n\n if ($isData && $rDef.$data) {\n $closingBraces += '}';\n out += ' if (' + $schemaValue + ' === undefined) { ' + $valid + ' = true; } else { ';\n\n if ($validateSchema) {\n $closingBraces += '}';\n out += ' ' + $valid + ' = ' + $definition + '.validateSchema(' + $schemaValue + '); if (' + $valid + ') { ';\n }\n }\n\n if ($inline) {\n if ($rDef.statements) {\n out += ' ' + $ruleValidate.validate + ' ';\n } else {\n out += ' ' + $valid + ' = ' + $ruleValidate.validate + '; ';\n }\n } else if ($macro) {\n var $it = it.util.copy(it);\n var $closingBraces = '';\n $it.level++;\n var $nextValid = 'valid' + $it.level;\n $it.schema = $ruleValidate.validate;\n $it.schemaPath = '';\n var $wasComposite = it.compositeRule;\n it.compositeRule = $it.compositeRule = true;\n var $code = it.validate($it).replace(/validate\\.schema/g, $validateCode);\n it.compositeRule = $it.compositeRule = $wasComposite;\n out += ' ' + $code;\n } else {\n var $$outStack = $$outStack || [];\n $$outStack.push(out);\n out = '';\n out += ' ' + $validateCode + '.call( ';\n\n if (it.opts.passContext) {\n out += 'this';\n } else {\n out += 'self';\n }\n\n if ($compile || $rDef.schema === false) {\n out += ' , ' + $data + ' ';\n } else {\n out += ' , ' + $schemaValue + ' , ' + $data + ' , validate.schema' + it.schemaPath + ' ';\n }\n\n out += ' , (dataPath || \\'\\')';\n\n if (it.errorPath != '\"\"') {\n out += ' + ' + it.errorPath;\n }\n\n var $parentData = $dataLvl ? 'data' + ($dataLvl - 1 || '') : 'parentData',\n $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';\n out += ' , ' + $parentData + ' , ' + $parentDataProperty + ' , rootData ) ';\n var def_callRuleValidate = out;\n out = $$outStack.pop();\n\n if ($rDef.errors === false) {\n out += ' ' + $valid + ' = ';\n\n if ($asyncKeyword) {\n out += 'await ';\n }\n\n out += '' + def_callRuleValidate + '; ';\n } else {\n if ($asyncKeyword) {\n $ruleErrs = 'customErrors' + $lvl;\n out += ' var ' + $ruleErrs + ' = null; try { ' + $valid + ' = await ' + def_callRuleValidate + '; } catch (e) { ' + $valid + ' = false; if (e instanceof ValidationError) ' + $ruleErrs + ' = e.errors; else throw e; } ';\n } else {\n out += ' ' + $ruleErrs + ' = null; ' + $valid + ' = ' + def_callRuleValidate + '; ';\n }\n }\n }\n\n if ($rDef.modifying) {\n out += ' if (' + $parentData + ') ' + $data + ' = ' + $parentData + '[' + $parentDataProperty + '];';\n }\n\n out += '' + $closingBraces;\n\n if ($rDef.valid) {\n if ($breakOnError) {\n out += ' if (true) { ';\n }\n } else {\n out += ' if ( ';\n\n if ($rDef.valid === undefined) {\n out += ' !';\n\n if ($macro) {\n out += '' + $nextValid;\n } else {\n out += '' + $valid;\n }\n } else {\n out += ' ' + !$rDef.valid + ' ';\n }\n\n out += ') { ';\n $errorKeyword = $rule.keyword;\n var $$outStack = $$outStack || [];\n $$outStack.push(out);\n out = '';\n var $$outStack = $$outStack || [];\n $$outStack.push(out);\n out = '';\n /* istanbul ignore else */\n\n if (it.createErrors !== false) {\n out += ' { keyword: \\'' + ($errorKeyword || 'custom') + '\\' , dataPath: (dataPath || \\'\\') + ' + it.errorPath + ' , schemaPath: ' + it.util.toQuotedString($errSchemaPath) + ' , params: { keyword: \\'' + $rule.keyword + '\\' } ';\n\n if (it.opts.messages !== false) {\n out += ' , message: \\'should pass \"' + $rule.keyword + '\" keyword validation\\' ';\n }\n\n if (it.opts.verbose) {\n out += ' , schema: validate.schema' + $schemaPath + ' , parentSchema: validate.schema' + it.schemaPath + ' , data: ' + $data + ' ';\n }\n\n out += ' } ';\n } else {\n out += ' {} ';\n }\n\n var __err = out;\n out = $$outStack.pop();\n\n if (!it.compositeRule && $breakOnError) {\n /* istanbul ignore if */\n if (it.async) {\n out += ' throw new ValidationError([' + __err + ']); ';\n } else {\n out += ' validate.errors = [' + __err + ']; return false; ';\n }\n } else {\n out += ' var err = ' + __err + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';\n }\n\n var def_customError = out;\n out = $$outStack.pop();\n\n if ($inline) {\n if ($rDef.errors) {\n if ($rDef.errors != 'full') {\n out += ' for (var ' + $i + '=' + $errs + '; ' + $i + '