@@ -13,8 +13,6 @@ module.exports = {
1313 ucs2length : require ( './ucs2length' ) ,
1414 varOccurences : varOccurences ,
1515 varReplace : varReplace ,
16- cleanUpCode : cleanUpCode ,
17- finalCleanUpCode : finalCleanUpCode ,
1816 schemaHasRules : schemaHasRules ,
1917 schemaHasRulesExcept : schemaHasRulesExcept ,
2018 schemaUnknownRules : schemaUnknownRules ,
@@ -139,42 +137,6 @@ function varReplace(str, dataVar, expr) {
139137}
140138
141139
142- var EMPTY_ELSE = / e l s e \s * { \s * } / g
143- , EMPTY_IF_NO_ELSE = / i f \s * \( [ ^ ) ] + \) \s * \{ \s * \} (? ! \s * e l s e ) / g
144- , EMPTY_IF_WITH_ELSE = / i f \s * \( ( [ ^ ) ] + ) \) \s * \{ \s * \} \s * e l s e (? ! \s * i f ) / g;
145- function cleanUpCode ( out ) {
146- return out . replace ( EMPTY_ELSE , '' )
147- . replace ( EMPTY_IF_NO_ELSE , '' )
148- . replace ( EMPTY_IF_WITH_ELSE , 'if (!($1))' ) ;
149- }
150-
151-
152- var ERRORS_REGEXP = / [ ^ v . ] e r r o r s / g
153- , REMOVE_ERRORS = / v a r e r r o r s = 0 ; | v a r v E r r o r s = n u l l ; | v a l i d a t e .e r r o r s = v E r r o r s ; / g
154- , REMOVE_ERRORS_ASYNC = / v a r e r r o r s = 0 ; | v a r v E r r o r s = n u l l ; / g
155- , RETURN_VALID = 'return errors === 0;'
156- , RETURN_TRUE = 'validate.errors = null; return true;'
157- , RETURN_ASYNC = / i f \( e r r o r s = = = 0 \) r e t u r n d a t a ; \s * e l s e t h r o w n e w V a l i d a t i o n E r r o r \( v E r r o r s \) ; /
158- , RETURN_DATA_ASYNC = 'return data;'
159- , ROOTDATA_REGEXP = / [ ^ A - Z a - z _ $ ] r o o t D a t a [ ^ A - Z a - z 0 - 9 _ $ ] / g
160- , REMOVE_ROOTDATA = / i f \( r o o t D a t a = = = u n d e f i n e d \) r o o t D a t a = d a t a ; / ;
161-
162- function finalCleanUpCode ( out , async ) {
163- var matches = out . match ( ERRORS_REGEXP ) ;
164- if ( matches && matches . length == 2 ) {
165- out = async
166- ? out . replace ( REMOVE_ERRORS_ASYNC , '' )
167- . replace ( RETURN_ASYNC , RETURN_DATA_ASYNC )
168- : out . replace ( REMOVE_ERRORS , '' )
169- . replace ( RETURN_VALID , RETURN_TRUE ) ;
170- }
171-
172- matches = out . match ( ROOTDATA_REGEXP ) ;
173- if ( ! matches || matches . length !== 3 ) return out ;
174- return out . replace ( REMOVE_ROOTDATA , '' ) ;
175- }
176-
177-
178140function schemaHasRules ( schema , rules ) {
179141 if ( typeof schema == 'boolean' ) return ! schema ;
180142 for ( var key in schema ) if ( rules [ key ] ) return true ;
0 commit comments