Skip to content

Commit

Permalink
Merge pull request #237 from icebob/bug-#236
Browse files Browse the repository at this point in the history
fix debug mode
  • Loading branch information
icebob authored Jun 1, 2021
2 parents 2fa314b + 03d296d commit d1bf0c3
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ class Validator {
if (!Array.isArray(plugins)) throw new Error("Plugins type must be array");
plugins.forEach(this.plugin.bind(this));
}

/* istanbul ignore next */
if (this.opts.debug) {
let formatter = function (code) { return code; };
if (typeof window === "undefined") {
formatter = require("./helpers/prettier");
}

this._formatter = formatter;
}
}
}

Expand Down Expand Up @@ -215,12 +225,7 @@ class Validator {

/* istanbul ignore next */
if (this.opts.debug) {
let formatter = function (code) { return code; };
if (typeof window === "undefined") // eslint-disable-line no-undef
formatter = require("./helpers/prettier");

context.fn.forEach((fn, i) => console.log(formatter(`// Context.fn[${i}]\n` + fn.toString()))); // eslint-disable-line no-console
console.log(formatter("// Main check function\n" + checkFn.toString())); // eslint-disable-line no-console
console.log(this._formatter("// Main check function\n" + checkFn.toString())); // eslint-disable-line no-console
}

this.cache.clear();
Expand Down Expand Up @@ -277,6 +282,11 @@ class Validator {
context.fn[rule.index] = fn.bind(this);
sourceCode.push(this.wrapRequiredCheckSourceCode(rule, innerSrc.replace(/%%INDEX%%/g, rule.index), context, resVar));
sourceCode.push(this.makeCustomValidator({vName: resVar, path: customPath, schema: rule.schema, context, messages: rule.messages, ruleIndex: rule.index}));

/* istanbul ignore next */
if (this.opts.debug) {
console.log(this._formatter(`// Context.fn[${rule.index}]\n` + fn.toString())); // eslint-disable-line no-console
}
}

return sourceCode.join("\n");
Expand Down

0 comments on commit d1bf0c3

Please sign in to comment.