summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/request/node_modules/har-validator/node_modules/ajv/scripts/compile-dots.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/request/node_modules/har-validator/node_modules/ajv/scripts/compile-dots.js')
-rw-r--r--deps/npm/node_modules/request/node_modules/har-validator/node_modules/ajv/scripts/compile-dots.js23
1 files changed, 20 insertions, 3 deletions
diff --git a/deps/npm/node_modules/request/node_modules/har-validator/node_modules/ajv/scripts/compile-dots.js b/deps/npm/node_modules/request/node_modules/har-validator/node_modules/ajv/scripts/compile-dots.js
index 7150bebfa7..e6a27dc397 100644
--- a/deps/npm/node_modules/request/node_modules/har-validator/node_modules/ajv/scripts/compile-dots.js
+++ b/deps/npm/node_modules/request/node_modules/har-validator/node_modules/ajv/scripts/compile-dots.js
@@ -1,4 +1,5 @@
//compile doT templates to js functions
+'use strict';
var glob = require('glob')
, fs = require('fs')
@@ -26,8 +27,13 @@ console.log('\n\nCompiling:');
var FUNCTION_NAME = /function\s+anonymous\s*\(it[^)]*\)\s*{/;
var OUT_EMPTY_STRING = /out\s*\+=\s*'\s*';/g;
var ISTANBUL = /\'(istanbul[^']+)\';/g;
-var VARS = ['$errs', '$valid', '$lvl', '$data', '$dataLvl',
- '$errorKeyword', '$closingBraces', '$schemaPath'];
+var ERROR_KEYWORD = /\$errorKeyword/g;
+var ERROR_KEYWORD_OR = /\$errorKeyword\s+\|\|/g;
+var VARS = [
+ '$errs', '$valid', '$lvl', '$data', '$dataLvl',
+ '$errorKeyword', '$closingBraces', '$schemaPath',
+ '$validate'
+];
files.forEach(function (f) {
var keyword = path.basename(f, '.jst');
@@ -38,6 +44,7 @@ files.forEach(function (f) {
.replace(OUT_EMPTY_STRING, '')
.replace(FUNCTION_NAME, 'function generate_' + keyword + '(it, $keyword) {')
.replace(ISTANBUL, '/* $1 */');
+ removeAlwaysFalsyInOr();
VARS.forEach(removeUnusedVar);
code = "'use strict';\nmodule.exports = " + code;
code = beautify(code, { indent_size: 2 }) + '\n';
@@ -47,10 +54,20 @@ files.forEach(function (f) {
function removeUnusedVar(v) {
v = v.replace(/\$/g, '\\$$');
var regexp = new RegExp(v + '[^A-Za-z0-9_$]', 'g');
- var count = (code.match(regexp) || []).length;
+ var count = occurrences(regexp);
if (count == 1) {
regexp = new RegExp('var\\s+' + v + '\\s*=[^;]+;|var\\s+' + v + ';');
code = code.replace(regexp, '');
}
}
+
+ function removeAlwaysFalsyInOr() {
+ var countUsed = occurrences(ERROR_KEYWORD);
+ var countOr = occurrences(ERROR_KEYWORD_OR);
+ if (countUsed == countOr + 1) code = code.replace(ERROR_KEYWORD_OR, '');
+ }
+
+ function occurrences(regexp) {
+ return (code.match(regexp) || []).length;
+ }
});