-
-
Notifications
You must be signed in to change notification settings - Fork 886
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
precompiled dot templates, dot is devDependency, closes #3
- Loading branch information
1 parent
5b62a32
commit 5f36f17
Showing
56 changed files
with
1,441 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
node ./bin/compile_dots.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//compile doT templates to js functions | ||
|
||
var glob = require('glob') | ||
, fs = require('fs') | ||
, path = require('path') | ||
, doT = require('dot') | ||
, beautify = require('js-beautify').js_beautify; | ||
|
||
var defs = fs.readFileSync(path.join(__dirname, '../lib/dot/definitions.def')); | ||
var files = glob.sync('../lib/dot/*.jst', { cwd: __dirname }); | ||
|
||
files.forEach(function (f) { | ||
var template = fs.readFileSync(path.join(__dirname, f)); | ||
var code = doT.compile(template, { definitions: defs }); | ||
code = "'use strict';\nmodule.exports = " + code.toString(); | ||
code = code.replace(/out\s*\+=\s*'\s*';/g, ''); | ||
code = beautify(code, { indent_size: 2 }) + '\n'; | ||
var targetFile = f.replace('../lib/dot', '').replace('.jst', '.js') | ||
, targetPath = path.join(__dirname, '../lib/dotjs', targetFile); | ||
fs.writeFileSync(targetPath, code); | ||
console.log('compiled', targetFile); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env bash | ||
./node_modules/.bin/watch 'node bin/compile_dots.js' ./lib/dot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict'; | ||
module.exports = function anonymous(it) { | ||
var out = ' '; | ||
var $lvl = it.level, | ||
$dataLvl = it.dataLevel, | ||
$schema = it.schema['$ref'], | ||
$schemaPath = it.schemaPath + '.' + '$ref', | ||
$breakOnError = !it.opts.allErrors; | ||
var $data = 'data' + ($dataLvl || ''), | ||
$valid = 'valid' + $lvl, | ||
$errs = 'errs' + $lvl; | ||
if (it.opts._debug) { | ||
out += ' console.log(\'Keyword ' + ('$ref') + '\'); '; | ||
} | ||
if ($schema == '#' || $schema == '#/') { | ||
if (it.isRoot) { | ||
if ($breakOnError && it.wasTop) { | ||
out += ' if (! ' + ('validate') + '(' + ($data) + ', (dataPath || \'\') + ' + (it.errorPath) + ') ) return false; else { '; | ||
} else { | ||
out += ' var errors' + ($lvl) + ' = validate.errors; if (! ' + ('validate') + '(' + ($data) + ', (dataPath || \'\') + ' + (it.errorPath) + ') ) { if (errors' + ($lvl) + ' !== null) validate.errors = errors' + ($lvl) + '.concat(validate.errors); errors = validate.errors.length; } '; | ||
if ($breakOnError) { | ||
out += ' else { '; | ||
} | ||
} | ||
} else { | ||
var $v = 'v' + $lvl; | ||
out += ' var ' + ($v) + ' = root.refVal[0]; if (! ' + ($v) + '(' + ($data) + ', (dataPath || \'\') + ' + (it.errorPath) + ') ) { if (validate.errors === null) validate.errors = ' + ($v) + '.errors; else validate.errors = validate.errors.concat(' + ($v) + '.errors); errors = validate.errors.length; } '; | ||
if ($breakOnError) { | ||
out += ' else { '; | ||
} | ||
} | ||
} else { | ||
var $refVal = it.resolveRef(it.baseId, $schema, it.rootId); | ||
if ($refVal === undefined) { | ||
if (it.wasTop && $breakOnError) { | ||
out += ' validate.errors = [ { keyword: \'' + ('$ref') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'can\\\'t resolve reference ' + ($schema) + '\' '; | ||
if (it.opts.verbose) { | ||
out += ', schema: \'' + ($schema) + '\', data: ' + ($data); | ||
} | ||
out += ' }]; return false; '; | ||
} else { | ||
out += ' var err = { keyword: \'' + ('$ref') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'can\\\'t resolve reference ' + ($schema) + '\' '; | ||
if (it.opts.verbose) { | ||
out += ', schema: \'' + ($schema) + '\', data: ' + ($data); | ||
} | ||
out += ' }; if (validate.errors === null) validate.errors = [err]; else validate.errors.push(err); errors++; '; | ||
} | ||
if ($breakOnError) { | ||
out += ' if (false) { '; | ||
} | ||
} else { | ||
var $v = 'v' + $lvl; | ||
out += ' var ' + ($v) + ' = ' + ($refVal) + '; if (! ' + ($v) + '(' + ($data) + ', (dataPath || \'\') + ' + (it.errorPath) + ') ) { if (validate.errors === null) validate.errors = ' + ($v) + '.errors; else validate.errors = validate.errors.concat(' + ($v) + '.errors); errors = validate.errors.length; } '; | ||
if ($breakOnError) { | ||
out += ' else { '; | ||
} | ||
} | ||
} | ||
return out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
These files are compiled dot templates from dot folder. | ||
|
||
Do NOT edit them directly, edit the templates and run `node bin/compile_dots` from main ajv folder. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
module.exports = function anonymous(it) { | ||
var out = ' '; | ||
var $lvl = it.level, | ||
$dataLvl = it.dataLevel, | ||
$schema = it.schema['allOf'], | ||
$schemaPath = it.schemaPath + '.' + 'allOf', | ||
$breakOnError = !it.opts.allErrors; | ||
var $data = 'data' + ($dataLvl || ''), | ||
$valid = 'valid' + $lvl, | ||
$errs = 'errs' + $lvl; | ||
if (it.opts._debug) { | ||
out += ' console.log(\'Keyword ' + ('allOf') + '\'); '; | ||
} | ||
var $it = it.util.copy(it), | ||
$closingBraces = ''; | ||
$it.level++; | ||
var arr1 = $schema; | ||
if (arr1) { | ||
var $sch, $i = -1, | ||
l1 = arr1.length - 1; | ||
while ($i < l1) { | ||
$sch = arr1[$i += 1]; | ||
if (it.util.schemaHasRules($sch, it.RULES.all)) { | ||
$it.schema = $sch; | ||
$it.schemaPath = $schemaPath + '[' + $i + ']'; | ||
out += ' ' + (it.validate($it)) + ' '; | ||
if ($breakOnError) { | ||
out += ' if (valid' + ($it.level) + ') { '; | ||
$closingBraces += '}'; | ||
} | ||
} | ||
} | ||
} | ||
if ($breakOnError) { | ||
out += ' ' + ($closingBraces.slice(0, -1)); | ||
} | ||
out = it.util.cleanUpCode(out); | ||
return out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
module.exports = function anonymous(it) { | ||
var out = ' '; | ||
var $lvl = it.level, | ||
$dataLvl = it.dataLevel, | ||
$schema = it.schema['anyOf'], | ||
$schemaPath = it.schemaPath + '.' + 'anyOf', | ||
$breakOnError = !it.opts.allErrors; | ||
var $data = 'data' + ($dataLvl || ''), | ||
$valid = 'valid' + $lvl, | ||
$errs = 'errs' + $lvl; | ||
if (it.opts._debug) { | ||
out += ' console.log(\'Keyword ' + ('anyOf') + '\'); '; | ||
} | ||
var $it = it.util.copy(it), | ||
$closingBraces = ''; | ||
$it.level++; | ||
var $noEmptySchema = $schema.every(function($sch) { | ||
return it.util.schemaHasRules($sch, it.RULES.all); | ||
}); | ||
if ($noEmptySchema) { | ||
out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = false; '; | ||
var arr1 = $schema; | ||
if (arr1) { | ||
var $sch, $i = -1, | ||
l1 = arr1.length - 1; | ||
while ($i < l1) { | ||
$sch = arr1[$i += 1]; | ||
$it.schema = $sch; | ||
$it.schemaPath = $schemaPath + '[' + $i + ']'; | ||
out += ' ' + (it.validate($it)) + ' ' + ($valid) + ' = ' + ($valid) + ' || valid' + ($it.level) + '; if (!' + ($valid) + ') { '; | ||
$closingBraces += '}'; | ||
} | ||
} | ||
out += ' ' + ($closingBraces) + ' if (' + ($valid) + ') { errors = ' + ($errs) + '; if (validate.errors !== null) { if (' + ($errs) + ') validate.errors.length = ' + ($errs) + '; else validate.errors = null; } '; | ||
if (it.opts.allErrors) { | ||
out += ' } '; | ||
} | ||
out = it.util.cleanUpCode(out); | ||
} else { | ||
if ($breakOnError) { | ||
out += ' if (true) { '; | ||
} | ||
} | ||
return out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
'use strict'; | ||
module.exports = function anonymous(it) { | ||
var out = ' '; | ||
var $lvl = it.level, | ||
$dataLvl = it.dataLevel, | ||
$schema = it.schema['dependencies'], | ||
$schemaPath = it.schemaPath + '.' + 'dependencies', | ||
$breakOnError = !it.opts.allErrors; | ||
var $data = 'data' + ($dataLvl || ''), | ||
$valid = 'valid' + $lvl, | ||
$errs = 'errs' + $lvl; | ||
if (it.opts._debug) { | ||
out += ' console.log(\'Keyword ' + ('dependencies') + '\'); '; | ||
} | ||
var $it = it.util.copy(it), | ||
$closingBraces = ''; | ||
$it.level++; | ||
var $schemaDeps = {}, | ||
$propertyDeps = {}; | ||
for ($property in $schema) { | ||
var $sch = $schema[$property]; | ||
var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps; | ||
$deps[$property] = $sch; | ||
} | ||
out += 'var ' + ($errs) + ' = errors;'; | ||
for (var $property in $propertyDeps) { | ||
out += ' if (' + ($data) + (it.util.getProperty($property)) + ' !== undefined) { '; | ||
$deps = $propertyDeps[$property]; | ||
out += ' if ( '; | ||
var arr1 = $deps; | ||
if (arr1) { | ||
var $dep, $i = -1, | ||
l1 = arr1.length - 1; | ||
while ($i < l1) { | ||
$dep = arr1[$i += 1]; | ||
if ($i) { | ||
out += ' || '; | ||
} | ||
out += ' ' + ($data) + (it.util.getProperty($dep)) + ' === undefined '; | ||
} | ||
} | ||
out += ') { '; | ||
if (it.wasTop && $breakOnError) { | ||
out += ' validate.errors = [ { keyword: \'' + ('dependencies') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \''; | ||
if ($deps.length == 1) { | ||
out += 'property ' + ($deps[0]) + ' is'; | ||
} else { | ||
out += 'properties ' + ($deps.join(", ")) + ' are'; | ||
} | ||
out += ' required when property ' + ($property) + ' is present\' '; | ||
if (it.opts.verbose) { | ||
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data); | ||
} | ||
out += ' }]; return false; '; | ||
} else { | ||
out += ' var err = { keyword: \'' + ('dependencies') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \''; | ||
if ($deps.length == 1) { | ||
out += 'property ' + ($deps[0]) + ' is'; | ||
} else { | ||
out += 'properties ' + ($deps.join(", ")) + ' are'; | ||
} | ||
out += ' required when property ' + ($property) + ' is present\' '; | ||
if (it.opts.verbose) { | ||
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data); | ||
} | ||
out += ' }; if (validate.errors === null) validate.errors = [err]; else validate.errors.push(err); errors++; '; | ||
} | ||
out += ' } '; | ||
if ($breakOnError) { | ||
$closingBraces += '}'; | ||
out += ' else { '; | ||
} | ||
out += ' }'; | ||
} | ||
for (var $property in $schemaDeps) { | ||
var $sch = $schemaDeps[$property]; | ||
if (it.util.schemaHasRules($sch, it.RULES.all)) { | ||
out += ' valid' + ($it.level) + ' = true; if (' + ($data) + '[\'' + ($property) + '\'] !== undefined) { '; | ||
$it.schema = $sch; | ||
$it.schemaPath = $schemaPath + "['" + it.util.escapeQuotes($property) + "']"; | ||
out += ' ' + (it.validate($it)) + ' } '; | ||
if ($breakOnError) { | ||
out += ' if (valid' + ($it.level) + ') { '; | ||
$closingBraces += '}'; | ||
} | ||
} | ||
} | ||
if ($breakOnError) { | ||
out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {'; | ||
} | ||
out = it.util.cleanUpCode(out); | ||
return out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
module.exports = function anonymous(it) { | ||
var out = ' '; | ||
var $lvl = it.level, | ||
$dataLvl = it.dataLevel, | ||
$schema = it.schema['enum'], | ||
$schemaPath = it.schemaPath + '.' + 'enum', | ||
$breakOnError = !it.opts.allErrors; | ||
var $data = 'data' + ($dataLvl || ''), | ||
$valid = 'valid' + $lvl, | ||
$errs = 'errs' + $lvl; | ||
if (it.opts._debug) { | ||
out += ' console.log(\'Keyword ' + ('enum') + '\'); '; | ||
} | ||
var $i = 'i' + $lvl; | ||
out += 'var enumSchema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ' , ' + ($valid) + ' = false;for (var ' + ($i) + '=0; ' + ($i) + '<enumSchema' + ($lvl) + '.length; ' + ($i) + '++) if (equal(' + ($data) + ', enumSchema' + ($lvl) + '[' + ($i) + '])) { ' + ($valid) + ' = true; break; } if (!' + ($valid) + ') { '; | ||
if (it.wasTop && $breakOnError) { | ||
out += ' validate.errors = [ { keyword: \'' + ('enum') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should be equal to one of values\' '; | ||
if (it.opts.verbose) { | ||
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data); | ||
} | ||
out += ' }]; return false; '; | ||
} else { | ||
out += ' var err = { keyword: \'' + ('enum') + '\', dataPath: (dataPath || \'\') + ' + (it.errorPath) + ', message: \'should be equal to one of values\' '; | ||
if (it.opts.verbose) { | ||
out += ', schema: validate.schema' + ($schemaPath) + ', data: ' + ($data); | ||
} | ||
out += ' }; if (validate.errors === null) validate.errors = [err]; else validate.errors.push(err); errors++; '; | ||
} | ||
out += ' }'; | ||
if ($breakOnError) { | ||
out += ' else { '; | ||
} | ||
return out; | ||
} |
Oops, something went wrong.