@@ -78,6 +78,16 @@ class Validator {
78
78
if ( ! Array . isArray ( plugins ) ) throw new Error ( "Plugins type must be array" ) ;
79
79
plugins . forEach ( this . plugin . bind ( this ) ) ;
80
80
}
81
+
82
+ /* istanbul ignore next */
83
+ if ( this . opts . debug ) {
84
+ let formatter = function ( code ) { return code ; } ;
85
+ if ( typeof window === "undefined" ) {
86
+ formatter = require ( "./helpers/prettier" ) ;
87
+ }
88
+
89
+ this . _formatter = formatter ;
90
+ }
81
91
}
82
92
}
83
93
@@ -215,12 +225,7 @@ class Validator {
215
225
216
226
/* istanbul ignore next */
217
227
if ( this . opts . debug ) {
218
- let formatter = function ( code ) { return code ; } ;
219
- if ( typeof window === "undefined" ) // eslint-disable-line no-undef
220
- formatter = require ( "./helpers/prettier" ) ;
221
-
222
- context . fn . forEach ( ( fn , i ) => console . log ( formatter ( `// Context.fn[${ i } ]\n` + fn . toString ( ) ) ) ) ; // eslint-disable-line no-console
223
- console . log ( formatter ( "// Main check function\n" + checkFn . toString ( ) ) ) ; // eslint-disable-line no-console
228
+ console . log ( this . _formatter ( "// Main check function\n" + checkFn . toString ( ) ) ) ; // eslint-disable-line no-console
224
229
}
225
230
226
231
this . cache . clear ( ) ;
@@ -277,6 +282,11 @@ class Validator {
277
282
context . fn [ rule . index ] = fn . bind ( this ) ;
278
283
sourceCode . push ( this . wrapRequiredCheckSourceCode ( rule , innerSrc . replace ( / % % I N D E X % % / g, rule . index ) , context , resVar ) ) ;
279
284
sourceCode . push ( this . makeCustomValidator ( { vName : resVar , path : customPath , schema : rule . schema , context, messages : rule . messages , ruleIndex : rule . index } ) ) ;
285
+
286
+ /* istanbul ignore next */
287
+ if ( this . opts . debug ) {
288
+ console . log ( this . _formatter ( `// Context.fn[${ rule . index } ]\n` + fn . toString ( ) ) ) ; // eslint-disable-line no-console
289
+ }
280
290
}
281
291
282
292
return sourceCode . join ( "\n" ) ;
0 commit comments