diff --git a/lib/compile/index.js b/lib/compile/index.js index 1bf9275..3ecdfed 100644 --- a/lib/compile/index.js +++ b/lib/compile/index.js @@ -44,7 +44,7 @@ function compile(schema, root, localRefs, baseId) { , defaults = [] , defaultsHash = {} , customRules = [] - , retainSourceCode = this._opts.retainSourceCode !== false; + , keepSourceCode = this._opts.sourceCode !== false; root = root || { schema: schema, refVal: refVal, refs: refs }; @@ -66,7 +66,7 @@ function compile(schema, root, localRefs, baseId) { cv.refVal = v.refVal; cv.root = v.root; cv.$async = v.$async; - if (retainSourceCode) cv.sourceCode = v.sourceCode; + if (keepSourceCode) cv.sourceCode = v.sourceCode; } return v; } finally { @@ -128,33 +128,32 @@ function compile(schema, root, localRefs, baseId) { : sourceCode; var makeValidate = new Function( + 'self', + 'RULES', + 'formats', + 'root', 'refVal', + 'defaults', + 'customRules', 'co', 'equal', 'ucs2length', - 'root', - 'formats', - 'customRules', 'ValidationError', - 'RULES', - 'defaults', - 'self', - 'validate', validateCode ); validate = makeValidate( + self, + RULES, + formats, + root, refVal, + defaults, + customRules, co, equal, ucs2length, - root, - formats, - customRules, - ValidationError, - RULES, - defaults, - self + ValidationError ); refVal[0] = validate; @@ -169,7 +168,7 @@ function compile(schema, root, localRefs, baseId) { validate.refVal = refVal; validate.root = isRoot ? validate : _root; if ($async) validate.$async = true; - if (retainSourceCode) validate.sourceCode = sourceCode; + if (keepSourceCode) validate.sourceCode = sourceCode; return validate; } diff --git a/lib/dot/validate.jst b/lib/dot/validate.jst index d7e56b0..c376e40 100644 --- a/lib/dot/validate.jst +++ b/lib/dot/validate.jst @@ -34,7 +34,7 @@ it.dataPathArr = [undefined]; }} - validate = + var validate = {{? $async }} {{? $es7 }} (async function @@ -178,6 +178,8 @@ return errors === 0; {{ /* don't edit, used in replace */ }} {{?}} }); + + return validate; {{??}} var {{=$valid}} = errors === errs_{{=$lvl}}; {{?}}