Skip to content

Commit

Permalink
remove code post-processing
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Jun 30, 2020
1 parent 140cfa6 commit 24d4f8f
Show file tree
Hide file tree
Showing 12 changed files with 0 additions and 94 deletions.
38 changes: 0 additions & 38 deletions lib/compile/util.js
Expand Up @@ -13,8 +13,6 @@ module.exports = {
ucs2length: require('./ucs2length'),
varOccurences: varOccurences,
varReplace: varReplace,
cleanUpCode: cleanUpCode,
finalCleanUpCode: finalCleanUpCode,
schemaHasRules: schemaHasRules,
schemaHasRulesExcept: schemaHasRulesExcept,
schemaUnknownRules: schemaUnknownRules,
Expand Down Expand Up @@ -139,42 +137,6 @@ function varReplace(str, dataVar, expr) {
}


var EMPTY_ELSE = /else\s*{\s*}/g
, EMPTY_IF_NO_ELSE = /if\s*\([^)]+\)\s*\{\s*\}(?!\s*else)/g
, EMPTY_IF_WITH_ELSE = /if\s*\(([^)]+)\)\s*\{\s*\}\s*else(?!\s*if)/g;
function cleanUpCode(out) {
return out.replace(EMPTY_ELSE, '')
.replace(EMPTY_IF_NO_ELSE, '')
.replace(EMPTY_IF_WITH_ELSE, 'if (!($1))');
}


var ERRORS_REGEXP = /[^v.]errors/g
, REMOVE_ERRORS = /var errors = 0;|var vErrors = null;|validate.errors = vErrors;/g
, REMOVE_ERRORS_ASYNC = /var errors = 0;|var vErrors = null;/g
, RETURN_VALID = 'return errors === 0;'
, RETURN_TRUE = 'validate.errors = null; return true;'
, RETURN_ASYNC = /if \(errors === 0\) return data;\s*else throw new ValidationError\(vErrors\);/
, RETURN_DATA_ASYNC = 'return data;'
, ROOTDATA_REGEXP = /[^A-Za-z_$]rootData[^A-Za-z0-9_$]/g
, REMOVE_ROOTDATA = /if \(rootData === undefined\) rootData = data;/;

function finalCleanUpCode(out, async) {
var matches = out.match(ERRORS_REGEXP);
if (matches && matches.length == 2) {
out = async
? out.replace(REMOVE_ERRORS_ASYNC, '')
.replace(RETURN_ASYNC, RETURN_DATA_ASYNC)
: out.replace(REMOVE_ERRORS, '')
.replace(RETURN_VALID, RETURN_TRUE);
}

matches = out.match(ROOTDATA_REGEXP);
if (!matches || matches.length !== 3) return out;
return out.replace(REMOVE_ROOTDATA, '');
}


function schemaHasRules(schema, rules) {
if (typeof schema == 'boolean') return !schema;
for (var key in schema) if (rules[key]) return true;
Expand Down
2 changes: 0 additions & 2 deletions lib/dot/allOf.jst
Expand Up @@ -30,5 +30,3 @@
{{= $closingBraces.slice(0,-1) }}
{{?}}
{{?}}

{{# def.cleanUp }}
2 changes: 0 additions & 2 deletions lib/dot/anyOf.jst
Expand Up @@ -39,8 +39,6 @@
} else {
{{# def.resetErrors }}
{{? it.opts.allErrors }} } {{?}}

{{# def.cleanUp }}
{{??}}
{{? $breakOnError }}
if (true) {
Expand Down
2 changes: 0 additions & 2 deletions lib/dot/contains.jst
Expand Up @@ -53,5 +53,3 @@ var {{=$valid}};
{{# def.resetErrors }}
{{?}}
{{? it.opts.allErrors }} } {{?}}

{{# def.cleanUp }}
6 changes: 0 additions & 6 deletions lib/dot/definitions.def
Expand Up @@ -112,12 +112,6 @@
#}}


{{## def.cleanUp: {{ out = it.util.cleanUpCode(out); }} #}}


{{## def.finalCleanUp: {{ out = it.util.finalCleanUpCode(out, $async); }} #}}


{{## def.$data:
{{
var $isData = it.opts.$data && $schema && $schema.$data
Expand Down
2 changes: 0 additions & 2 deletions lib/dot/dependencies.jst
Expand Up @@ -76,5 +76,3 @@ var missing{{=$lvl}};
{{= $closingBraces }}
if ({{=$errs}} == errors) {
{{?}}

{{# def.cleanUp }}
2 changes: 0 additions & 2 deletions lib/dot/if.jst
Expand Up @@ -65,8 +65,6 @@
{{# def.extraError:'if' }}
}
{{? $breakOnError }} else { {{?}}

{{# def.cleanUp }}
{{??}}
{{? $breakOnError }}
if (true) {
Expand Down
2 changes: 0 additions & 2 deletions lib/dot/items.jst
Expand Up @@ -96,5 +96,3 @@ var {{=$valid}};
{{= $closingBraces }}
if ({{=$errs}} == errors) {
{{?}}

{{# def.cleanUp }}
2 changes: 0 additions & 2 deletions lib/dot/properties.jst
Expand Up @@ -240,5 +240,3 @@ var {{=$nextValid}} = true;
{{= $closingBraces }}
if ({{=$errs}} == errors) {
{{?}}

{{# def.cleanUp }}
2 changes: 0 additions & 2 deletions lib/dot/propertyNames.jst
Expand Up @@ -50,5 +50,3 @@ var {{=$errs}} = errors;
{{= $closingBraces }}
if ({{=$errs}} == errors) {
{{?}}

{{# def.cleanUp }}
6 changes: 0 additions & 6 deletions lib/dot/validate.jst
Expand Up @@ -254,12 +254,6 @@
var {{=$valid}} = errors === errs_{{=$lvl}};
{{?}}

{{# def.cleanUp }}

{{? $top }}
{{# def.finalCleanUp }}
{{?}}

{{
function $shouldUseGroup($rulesGroup) {
var rules = $rulesGroup.rules;
Expand Down
28 changes: 0 additions & 28 deletions spec/issues/388_code_clean-up.spec.js

This file was deleted.

0 comments on commit 24d4f8f

Please sign in to comment.