.6-淺析webpack源碼之validateSchema模塊


validateSchema模塊

 

  首先來看錯誤檢測:

    const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, options);
    if(webpackOptionsValidationErrors.length) {
        throw new WebpackOptionsValidationError(webpackOptionsValidationErrors);
    }

  可以注意到,這里傳了兩個參數,其實第一個參數來源於一個JSON文件:

    const webpackOptionsSchema = require("../schemas/webpackOptionsSchema.json");

  這個JSON文件非常大,可以觀察一下部分內容:

{
    "plugins": { "description": "Add additional plugins to the compiler.", "type": "array" }, "resolve": { "description": "Options for the resolver", "anyOf": [ { "$ref": "#/definitions/resolve" } ] }, "required": [ "entry" ], "type": "object" }

  從描述可以猜測,這里的key對應options中的key,value就是檢測方式。

  比如說entry放到required代表是必須的,plugins的type為array代表這個鍵必須是一個數組,而$ref代表一個路徑映射,即#/definnitions/resolve。

  在JSON文件的開頭有一個definitions,其中resolve對應的內容如下:

{
    "definitions": { "resolve": { "additionalProperties": false, "properties": { "alias": { // ...  } // ...  }, "type": "object" } } }

  簡單明了,就不多解釋了。

 

  下面進入validateSchema模塊,流程如圖:

  

  內部代碼簡化如下:

const Ajv = require("ajv");
const ajv = new Ajv({
    errorDataPath: "configuration",
    allErrors: true,
    verbose: true
});
require("ajv-keywords")(ajv, ["instanceof"]);
require("../schemas/ajv.absolutePath")(ajv);

function validateSchema(schema, options) {
    // 仍然是多配置與單配置
    if(Array.isArray(options)) { /*...*/ } 
    else {
        return validateObject(schema, options);
    }
}

function validateObject(schema, options) {
    // 轉換JSON文件
    const validate = ajv.compile(schema);
    // 檢測配置對象
    const valid = validate(options);
    // 返回錯誤對象
    return valid ? [] : filterErrors(validate.errors);
}

function filterErrors(errors) { /*...*/ }
module.exports = validateSchema;

  這里引入的ajv模塊是一個工具,就像之前的JSON5一樣,作用是將一個JSON配置文件轉換成一個對象,用於檢測對象的合法性。

  在github上,該工具的Getting started如圖所示:

  

  簡直跟源碼中的使用過程一模一樣,所以有興趣的可以自己去看看教程學一下。

  

  由於JSON十分巨大,所以編譯后的對象也十分巨大,這里根據vue腳手架中的配置,只看常規的參數是如何進行檢測的,比如說devServer、devtool、entry、module、output、plugins、resolve,測試代碼如下:

var Ajv = require('ajv');
const ajv = new Ajv({
    errorDataPath: "configuration",
    allErrors: true,
    verbose: true
});
// 簡化后的JSON文件
const json = require('./tmp.json');
const validate = ajv.compile(json);

  打包后嘗試獲取生成的validate函數,整理后源碼如下:

(function(self, RULES, formats, root, refVal, defaults, customRules, co, equal, ucs2length, ValidationError) {
    var refVal0 = refVal[0];
    // ...
    var refVal13 = refVal[13];
    var validate = (function(data, dataPath, parentData, parentDataProperty, rootData) {
        'use strict';
        // 負責收集錯誤信息
        var vErrors = null;
        // 負責對錯誤進行計數
        var errors = 0;
        if (rootData === undefined) rootData = data;
        // 這是根級對象
        if ((data && typeof data === "object" && !Array.isArray(data))) {
            var errs__0 = errors;
            var valid1 = true;
            for (var key0 in data) { /*...*/ }
            // 在這里進行檢測
            // 每出現一個錯誤errors+1並記錄vErrors中
            var data1 = data.devServer;
            if (data1 !== undefined) { /*...*/ }
            var data1 = data.devtool;
            if (data1 !== undefined) { /*...*/ }
            var data1 = data.entry;
            if (data1 === undefined) { /*...*/ } 
            else { /*...*/ }
            var data1 = data.module;
            if (data1 !== undefined) { /*...*/ }
            var data1 = data.output;
            if (data1 !== undefined) { /*...*/ }
            var data1 = data.plugins;
            if (data1 !== undefined) { /*...*/ }
            var data1 = data.resolve;
            if (data1 !== undefined) { /*...*/ }
        } else { /*...*/ }
        validate.errors = vErrors;
        // 判斷是否產生錯誤
        return errors === 0;
    });
    return validate;
})

  調用validate(options),options在函數中就相當於那個data,validate會依次從data中取出需要校驗的key,按照JSON文件中的規則進行判斷。

  這里有一個比較麻煩的點,就是頂部的refVal,由於這是一個內部的IIFE,所以從這里看不出refVal數組如何定義的。憑借我的聰明才智,還是從源碼中獲取到了對應的定義:

  

  打開后,其實是一堆validate函數,所以就不展開看了。

  其實validate並不只有這么多,其中還可以分為特殊校驗器和公共校驗器,其中公共校驗器不會針對特殊的鍵來進行校驗,在這里可以先列出來。(友情警告:千萬不要點開!!!)

 

refVal1

        if ((data && typeof data === "object" && !Array.isArray(data))) {
            if (Object.keys(data).length < 1) {
                var err = { keyword: 'minProperties', dataPath: (dataPath || '') + "", schemaPath: '#/oneOf/0/minProperties', params: { limit: 1 }, message: 'should NOT have less than 1 properties', schema: 1, parentSchema: validate.schema.oneOf[0], data: data };
                if (vErrors === null) vErrors = [err];
                else vErrors.push(err);
                errors++;
            }
            var errs__1 = errors;
            var valid2 = true;
            for (var key1 in data) {
                var data1 = data[key1];
                var errs_2 = errors;
                var errs__2 = errors;
                var prevValid2 = false;
                var valid2 = false;
                var errs_3 = errors;
                if (typeof data1 === "string") {
                    if (ucs2length(data1) < 1) {
                        var err = { keyword: 'minLength', dataPath: (dataPath || '') + '[\'' + key1 + '\']', schemaPath: '#/oneOf/0/additionalProperties/oneOf/0/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: validate.schema.oneOf[0].additionalProperties.oneOf[0], data: data1 };
                        if (vErrors === null) vErrors = [err];
                        else vErrors.push(err);
                        errors++;
                    }
                } else {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '[\'' + key1 + '\']', schemaPath: '#/oneOf/0/additionalProperties/oneOf/0/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.oneOf[0].additionalProperties.oneOf[0].type, parentSchema: validate.schema.oneOf[0].additionalProperties.oneOf[0], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid3 = errors === errs_3;
                if (valid3) valid2 = prevValid2 = true;
                var errs_3 = errors;
                var errs__3 = errors;
                var valid3 = false;
                var errs_4 = errors;
                var errs_5 = errors;
                if (Array.isArray(data1)) {
                    if (data1.length < 1) {
                        var err = { keyword: 'minItems', dataPath: (dataPath || '') + '[\'' + key1 + '\']', schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/minItems', params: { limit: 1 }, message: 'should NOT have less than 1 items', schema: 1, parentSchema: refVal2, data: data1 };
                        if (vErrors === null) vErrors = [err];
                        else vErrors.push(err);
                        errors++;
                    }
                    var valid5 = true;
                    if (data1.length > 1) {
                        var i = data1.length,
                            j;
                        outer: for (; i--;) { for (j = i; j--;) { if (equal(data1[i], data1[j])) { valid5 = false; break outer; } } }
                    }
                    if (!valid5) {
                        var err = { keyword: 'uniqueItems', dataPath: (dataPath || '') + '[\'' + key1 + '\']', schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/uniqueItems', params: { i: i, j: j }, message: 'should NOT have duplicate items (items ## ' + j + ' and ' + i + ' are identical)', schema: true, parentSchema: refVal2, data: data1 };
                        if (vErrors === null) vErrors = [err];
                        else vErrors.push(err);
                        errors++;
                    }
                    var errs__5 = errors;
                    var valid5;
                    for (var i5 = 0; i5 < data1.length; i5++) {
                        var data2 = data1[i5];
                        var errs_6 = errors;
                        if (typeof data2 === "string") {
                            if (ucs2length(data2) < 1) {
                                var err = { keyword: 'minLength', dataPath: (dataPath || '') + '[\'' + key1 + '\'][' + i5 + ']', schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal2.items, data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                        } else {
                            var err = { keyword: 'type', dataPath: (dataPath || '') + '[\'' + key1 + '\'][' + i5 + ']', schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal2.items.type, parentSchema: refVal2.items, data: data2 };
                            if (vErrors === null) vErrors = [err];
                            else vErrors.push(err);
                            errors++;
                        }
                        var valid6 = errors === errs_6;
                    }
                } else {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '[\'' + key1 + '\']', schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal2.type, parentSchema: refVal2, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid5 = errors === errs_5;
                var valid4 = errors === errs_4;
                valid3 = valid3 || valid4;
                if (!valid3) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '[\'' + key1 + '\']', schemaPath: '#/oneOf/0/additionalProperties/oneOf/1/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.oneOf[0].additionalProperties.oneOf[1].anyOf, parentSchema: validate.schema.oneOf[0].additionalProperties.oneOf[1], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__3;
                    if (vErrors !== null) {
                        if (errs__3) vErrors.length = errs__3;
                        else vErrors = null;
                    }
                }
                var valid3 = errors === errs_3;
                if (valid3 && prevValid2) valid2 = false;
                else { if (valid3) valid2 = prevValid2 = true; }
                if (!valid2) {
                    var err = { keyword: 'oneOf', dataPath: (dataPath || '') + '[\'' + key1 + '\']', schemaPath: '#/oneOf/0/additionalProperties/oneOf', params: {}, message: 'should match exactly one schema in oneOf', schema: validate.schema.oneOf[0].additionalProperties.oneOf, parentSchema: validate.schema.oneOf[0].additionalProperties, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__2;
                    if (vErrors !== null) {
                        if (errs__2) vErrors.length = errs__2;
                        else vErrors = null;
                    }
                }
                var valid2 = errors === errs_2;
            }
        } else {
            var err = { keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/oneOf/0/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.oneOf[0].type, parentSchema: validate.schema.oneOf[0], data: data };
            if (vErrors === null) vErrors = [err];
            else vErrors.push(err);
            errors++;
        }
        var valid1 = errors === errs_1;
        if (valid1) valid0 = prevValid0 = true;
        var errs_1 = errors;
        if (typeof data === "string") {
            if (ucs2length(data) < 1) {
                var err = { keyword: 'minLength', dataPath: (dataPath || '') + "", schemaPath: '#/oneOf/1/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: validate.schema.oneOf[1], data: data };
                if (vErrors === null) vErrors = [err];
                else vErrors.push(err);
                errors++;
            }
        } else {
            var err = { keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/oneOf/1/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.oneOf[1].type, parentSchema: validate.schema.oneOf[1], data: data };
            if (vErrors === null) vErrors = [err];
            else vErrors.push(err);
            errors++;
        }
        var valid1 = errors === errs_1;
        if (valid1 && prevValid0) valid0 = false;
        else {
            if (valid1) valid0 = prevValid0 = true;
            var errs_1 = errors;
            var errs__1 = errors;
            var valid1 = false;
            var errs_2 = errors;
            var errs_3 = errors;
            if (Array.isArray(data)) {
                if (data.length < 1) {
                    var err = { keyword: 'minItems', dataPath: (dataPath || '') + "", schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/minItems', params: { limit: 1 }, message: 'should NOT have less than 1 items', schema: 1, parentSchema: refVal[2], data: data };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid3 = true;
                if (data.length > 1) {
                    var i = data.length,
                        j;
                    outer: for (; i--;) { for (j = i; j--;) { if (equal(data[i], data[j])) { valid3 = false; break outer; } } }
                }
                if (!valid3) {
                    var err = { keyword: 'uniqueItems', dataPath: (dataPath || '') + "", schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/uniqueItems', params: { i: i, j: j }, message: 'should NOT have duplicate items (items ## ' + j + ' and ' + i + ' are identical)', schema: true, parentSchema: refVal[2], data: data };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var errs__3 = errors;
                var valid3;
                for (var i3 = 0; i3 < data.length; i3++) {
                    var data1 = data[i3];
                    var errs_4 = errors;
                    if (typeof data1 === "string") {
                        if (ucs2length(data1) < 1) {
                            var err = { keyword: 'minLength', dataPath: (dataPath || '') + '[' + i3 + ']', schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal[2].items, data: data1 };
                            if (vErrors === null) vErrors = [err];
                            else vErrors.push(err);
                            errors++;
                        }
                    } else {
                        var err = { keyword: 'type', dataPath: (dataPath || '') + '[' + i3 + ']', schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal[2].items.type, parentSchema: refVal[2].items, data: data1 };
                        if (vErrors === null) vErrors = [err];
                        else vErrors.push(err);
                        errors++;
                    }
                    var valid4 = errors === errs_4;
                }
            } else {
                var err = { keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal[2].type, parentSchema: refVal[2], data: data };
                if (vErrors === null) vErrors = [err];
                else vErrors.push(err);
                errors++;
            }
            var valid3 = errors === errs_3;
            var valid2 = errors === errs_2;
            valid1 = valid1 || valid2;
            if (!valid1) {
                var err = { keyword: 'anyOf', dataPath: (dataPath || '') + "", schemaPath: '#/oneOf/2/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.oneOf[2].anyOf, parentSchema: validate.schema.oneOf[2], data: data };
                if (vErrors === null) vErrors = [err];
                else vErrors.push(err);
                errors++;
            } else {
                errors = errs__1;
                if (vErrors !== null) {
                    if (errs__1) vErrors.length = errs__1;
                    else vErrors = null;
                }
            }
            var valid1 = errors === errs_1;
            if (valid1 && prevValid0) valid0 = false;
            else {
                if (valid1) valid0 = prevValid0 = true;
                var valid1 = true;
                if (valid1 && prevValid0) valid0 = false;
                else { if (valid1) valid0 = prevValid0 = true; }
            }
        }
        if (!valid0) {
            var err = { keyword: 'oneOf', dataPath: (dataPath || '') + "", schemaPath: '#/oneOf', params: {}, message: 'should match exactly one schema in oneOf', schema: validate.schema.oneOf, parentSchema: validate.schema, data: data };
            if (vErrors === null) vErrors = [err];
            else vErrors.push(err);
            errors++;
        } else {
            errors = errs__0;
            if (vErrors !== null) {
                if (errs__0) vErrors.length = errs__0;
                else vErrors = null;
            }
        }
View Code

規則:

1.數據可以為字符串、對象、數組

2.字符串必須為非空字符串

3.數組必須是非空數組,元素必須是非空字符串且不能重復

4.如果是對象則至少要有2個鍵,鍵的規則滿足2、3

 

refVal3

if ((data && typeof data === "object" && !Array.isArray(data))) {
            var errs__0 = errors;
            var valid1 = true;
            for (var key0 in data) {
                var isAdditional0 = !(false || validate.schema.properties[key0]);
                if (isAdditional0) {
                    valid1 = false;
                    var err = { keyword: 'additionalProperties', dataPath: (dataPath || '') + "", schemaPath: '#/additionalProperties', params: { additionalProperty: '' + key0 + '' }, message: 'should NOT have additional properties', schema: false, parentSchema: validate.schema, data: data };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
            }
            var data1 = data.exprContextCritical;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.exprContextCritical', schemaPath: '#/properties/exprContextCritical/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.exprContextCritical.type, parentSchema: validate.schema.properties.exprContextCritical, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.exprContextRecursive;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.exprContextRecursive', schemaPath: '#/properties/exprContextRecursive/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.exprContextRecursive.type, parentSchema: validate.schema.properties.exprContextRecursive, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            if (data.exprContextRegExp !== undefined) { var errs_1 = errors; var valid1 = errors === errs_1; }
            var data1 = data.exprContextRequest;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "string") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.exprContextRequest', schemaPath: '#/properties/exprContextRequest/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.exprContextRequest.type, parentSchema: validate.schema.properties.exprContextRequest, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.loaders;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                if (!refVal4(data1, (dataPath || '') + '.loaders', data, 'loaders', rootData)) {
                    if (vErrors === null) vErrors = refVal4.errors;
                    else vErrors = vErrors.concat(refVal4.errors);
                    errors = vErrors.length;
                }
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.loaders', schemaPath: '#/properties/loaders/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.loaders.anyOf, parentSchema: validate.schema.properties.loaders, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            if (data.noParse !== undefined) { var errs_1 = errors; var valid1 = errors === errs_1; }
            if (data.rules !== undefined) {
                var errs_1 = errors;
                var errs_2 = errors;
                if (!refVal[4](data.rules, (dataPath || '') + '.rules', data, 'rules', rootData)) {
                    if (vErrors === null) vErrors = refVal[4].errors;
                    else vErrors = vErrors.concat(refVal[4].errors);
                    errors = vErrors.length;
                }
                var valid2 = errors === errs_2;
                var valid1 = errors === errs_1;
            }
            var data1 = data.unknownContextCritical;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.unknownContextCritical', schemaPath: '#/properties/unknownContextCritical/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.unknownContextCritical.type, parentSchema: validate.schema.properties.unknownContextCritical, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.unknownContextRecursive;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.unknownContextRecursive', schemaPath: '#/properties/unknownContextRecursive/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.unknownContextRecursive.type, parentSchema: validate.schema.properties.unknownContextRecursive, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            if (data.unknownContextRegExp !== undefined) { var errs_1 = errors; var valid1 = errors === errs_1; }
            var data1 = data.unknownContextRequest;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "string") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.unknownContextRequest', schemaPath: '#/properties/unknownContextRequest/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.unknownContextRequest.type, parentSchema: validate.schema.properties.unknownContextRequest, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            if (data.unsafeCache !== undefined) { var errs_1 = errors; var valid1 = errors === errs_1; }
            var data1 = data.wrappedContextCritical;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.wrappedContextCritical', schemaPath: '#/properties/wrappedContextCritical/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.wrappedContextCritical.type, parentSchema: validate.schema.properties.wrappedContextCritical, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.wrappedContextRecursive;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.wrappedContextRecursive', schemaPath: '#/properties/wrappedContextRecursive/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.wrappedContextRecursive.type, parentSchema: validate.schema.properties.wrappedContextRecursive, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.strictExportPresence;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.strictExportPresence', schemaPath: '#/properties/strictExportPresence/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.strictExportPresence.type, parentSchema: validate.schema.properties.strictExportPresence, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.strictThisContextOnImports;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.strictThisContextOnImports', schemaPath: '#/properties/strictThisContextOnImports/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.strictThisContextOnImports.type, parentSchema: validate.schema.properties.strictThisContextOnImports, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
        } else {
            var err = { keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.type, parentSchema: validate.schema, data: data };
            if (vErrors === null) vErrors = [err];
            else vErrors.push(err);
            errors++;
        }
View Code

規則:

1.檢測了大量不知道的屬性

2.loaders,rules屬性調用refVal4校驗

 

refVal4

if (Array.isArray(data)) {
            var errs__0 = errors;
            var valid0;
            for (var i0 = 0; i0 < data.length; i0++) {
                var data1 = data[i0];
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                if (!refVal5(data1, (dataPath || '') + '[' + i0 + ']', data, i0, rootData)) {
                    if (vErrors === null) vErrors = refVal5.errors;
                    else vErrors = vErrors.concat(refVal5.errors);
                    errors = vErrors.length;
                }
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '[' + i0 + ']', schemaPath: '#/items/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.items.anyOf, parentSchema: validate.schema.items, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
        } else {
            var err = { keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/type', params: { type: 'array' }, message: 'should be array', schema: validate.schema.type, parentSchema: validate.schema, data: data };
            if (vErrors === null) vErrors = [err];
            else vErrors.push(err);
            errors++;
        }
View Code

規則:

1.必須為數組

2.數組元素調用refVal5校驗

 

refVal5

if ((data && typeof data === "object" && !Array.isArray(data))) {
            var errs__0 = errors;
            var valid1 = true;
            for (var key0 in data) {
                var isAdditional0 = !(false || validate.schema.properties[key0]);
                if (isAdditional0) {
                    valid1 = false;
                    var err = { keyword: 'additionalProperties', dataPath: (dataPath || '') + "", schemaPath: '#/additionalProperties', params: { additionalProperty: '' + key0 + '' }, message: 'should NOT have additional properties', schema: false, parentSchema: validate.schema, data: data };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
            }
            var data1 = data.enforce;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var schema1 = validate.schema.properties.enforce.enum;
                var valid1;
                valid1 = false;
                for (var i1 = 0; i1 < schema1.length; i1++)
                    if (equal(data1, schema1[i1])) { valid1 = true; break; }
                if (!valid1) {
                    var err = { keyword: 'enum', dataPath: (dataPath || '') + '.enforce', schemaPath: '#/properties/enforce/enum', params: { allowedValues: schema1 }, message: 'should be equal to one of the allowed values', schema: validate.schema.properties.enforce.enum, parentSchema: validate.schema.properties.enforce, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            if (data.exclude !== undefined) {
                var errs_1 = errors;
                var errs_2 = errors;
                if (!refVal6(data.exclude, (dataPath || '') + '.exclude', data, 'exclude', rootData)) {
                    if (vErrors === null) vErrors = refVal6.errors;
                    else vErrors = vErrors.concat(refVal6.errors);
                    errors = vErrors.length;
                }
                var valid2 = errors === errs_2;
                var valid1 = errors === errs_1;
            }
            if (data.include !== undefined) {
                var errs_1 = errors;
                var errs_2 = errors;
                if (!refVal[6](data.include, (dataPath || '') + '.include', data, 'include', rootData)) {
                    if (vErrors === null) vErrors = refVal[6].errors;
                    else vErrors = vErrors.concat(refVal[6].errors);
                    errors = vErrors.length;
                }
                var valid2 = errors === errs_2;
                var valid1 = errors === errs_1;
            }
            if (data.issuer !== undefined) {
                var errs_1 = errors;
                var errs_2 = errors;
                if (!refVal[6](data.issuer, (dataPath || '') + '.issuer', data, 'issuer', rootData)) {
                    if (vErrors === null) vErrors = refVal[6].errors;
                    else vErrors = vErrors.concat(refVal[6].errors);
                    errors = vErrors.length;
                }
                var valid2 = errors === errs_2;
                var valid1 = errors === errs_1;
            }
            var data1 = data.loader;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                var errs_3 = errors;
                if (typeof data1 === "string") {
                    if (ucs2length(data1) < 1) {
                        var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.loader', schemaPath: '#/definitions/ruleSet-loader/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal7, data: data1 };
                        if (vErrors === null) vErrors = [err];
                        else vErrors.push(err);
                        errors++;
                    }
                } else {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.loader', schemaPath: '#/definitions/ruleSet-loader/type', params: { type: 'string' }, message: 'should be string', schema: refVal7.type, parentSchema: refVal7, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid3 = errors === errs_3;
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var errs_2 = errors;
                    if (!refVal8(data1, (dataPath || '') + '.loader', data, 'loader', rootData)) {
                        if (vErrors === null) vErrors = refVal8.errors;
                        else vErrors = vErrors.concat(refVal8.errors);
                        errors = vErrors.length;
                    }
                    var valid2 = errors === errs_2;
                    valid1 = valid1 || valid2;
                }
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.loader', schemaPath: '#/properties/loader/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.loader.anyOf, parentSchema: validate.schema.properties.loader, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.loaders;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                if (!refVal[8](data1, (dataPath || '') + '.loaders', data, 'loaders', rootData)) {
                    if (vErrors === null) vErrors = refVal[8].errors;
                    else vErrors = vErrors.concat(refVal[8].errors);
                    errors = vErrors.length;
                }
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.loaders', schemaPath: '#/properties/loaders/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.loaders.anyOf, parentSchema: validate.schema.properties.loaders, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.oneOf;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                if (!refVal[4](data1, (dataPath || '') + '.oneOf', data, 'oneOf', rootData)) {
                    if (vErrors === null) vErrors = refVal[4].errors;
                    else vErrors = vErrors.concat(refVal[4].errors);
                    errors = vErrors.length;
                }
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.oneOf', schemaPath: '#/properties/oneOf/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.oneOf.anyOf, parentSchema: validate.schema.properties.oneOf, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.options;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                var errs_3 = errors;
                var errs__3 = errors;
                var valid3 = false;
                var errs_4 = errors;
                if ((!data1 || typeof data1 !== "object" || Array.isArray(data1))) {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.options', schemaPath: '#/definitions/ruleSet-query/anyOf/0/type', params: { type: 'object' }, message: 'should be object', schema: refVal9.anyOf[0].type, parentSchema: refVal9.anyOf[0], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid4 = errors === errs_4;
                valid3 = valid3 || valid4;
                if (!valid3) {
                    var errs_4 = errors;
                    if (typeof data1 !== "string") {
                        var err = { keyword: 'type', dataPath: (dataPath || '') + '.options', schemaPath: '#/definitions/ruleSet-query/anyOf/1/type', params: { type: 'string' }, message: 'should be string', schema: refVal9.anyOf[1].type, parentSchema: refVal9.anyOf[1], data: data1 };
                        if (vErrors === null) vErrors = [err];
                        else vErrors.push(err);
                        errors++;
                    }
                    var valid4 = errors === errs_4;
                    valid3 = valid3 || valid4;
                }
                if (!valid3) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.options', schemaPath: '#/definitions/ruleSet-query/anyOf', params: {}, message: 'should match some schema in anyOf', schema: refVal9.anyOf, parentSchema: refVal9, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__3;
                    if (vErrors !== null) {
                        if (errs__3) vErrors.length = errs__3;
                        else vErrors = null;
                    }
                }
                var valid3 = errors === errs_3;
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.options', schemaPath: '#/properties/options/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.options.anyOf, parentSchema: validate.schema.properties.options, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.parser;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) { var errs__1 = errors; var valid2 = true; } else {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.parser', schemaPath: '#/properties/parser/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.properties.parser.type, parentSchema: validate.schema.properties.parser, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.query;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                var errs_3 = errors;
                var errs__3 = errors;
                var valid3 = false;
                var errs_4 = errors;
                if ((!data1 || typeof data1 !== "object" || Array.isArray(data1))) {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.query', schemaPath: '#/definitions/ruleSet-query/anyOf/0/type', params: { type: 'object' }, message: 'should be object', schema: refVal[9].anyOf[0].type, parentSchema: refVal[9].anyOf[0], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid4 = errors === errs_4;
                valid3 = valid3 || valid4;
                if (!valid3) {
                    var errs_4 = errors;
                    if (typeof data1 !== "string") {
                        var err = { keyword: 'type', dataPath: (dataPath || '') + '.query', schemaPath: '#/definitions/ruleSet-query/anyOf/1/type', params: { type: 'string' }, message: 'should be string', schema: refVal[9].anyOf[1].type, parentSchema: refVal[9].anyOf[1], data: data1 };
                        if (vErrors === null) vErrors = [err];
                        else vErrors.push(err);
                        errors++;
                    }
                    var valid4 = errors === errs_4;
                    valid3 = valid3 || valid4;
                }
                if (!valid3) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.query', schemaPath: '#/definitions/ruleSet-query/anyOf', params: {}, message: 'should match some schema in anyOf', schema: refVal[9].anyOf, parentSchema: refVal[9], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__3;
                    if (vErrors !== null) {
                        if (errs__3) vErrors.length = errs__3;
                        else vErrors = null;
                    }
                }
                var valid3 = errors === errs_3;
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.query', schemaPath: '#/properties/query/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.query.anyOf, parentSchema: validate.schema.properties.query, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            if (data.resource !== undefined) {
                var errs_1 = errors;
                var errs_2 = errors;
                if (!refVal[6](data.resource, (dataPath || '') + '.resource', data, 'resource', rootData)) {
                    if (vErrors === null) vErrors = refVal[6].errors;
                    else vErrors = vErrors.concat(refVal[6].errors);
                    errors = vErrors.length;
                }
                var valid2 = errors === errs_2;
                var valid1 = errors === errs_1;
            }
            var data1 = data.resourceQuery;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                if (!refVal[6](data1, (dataPath || '') + '.resourceQuery', data, 'resourceQuery', rootData)) {
                    if (vErrors === null) vErrors = refVal[6].errors;
                    else vErrors = vErrors.concat(refVal[6].errors);
                    errors = vErrors.length;
                }
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.resourceQuery', schemaPath: '#/properties/resourceQuery/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.resourceQuery.anyOf, parentSchema: validate.schema.properties.resourceQuery, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.compiler;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                if (!refVal[6](data1, (dataPath || '') + '.compiler', data, 'compiler', rootData)) {
                    if (vErrors === null) vErrors = refVal[6].errors;
                    else vErrors = vErrors.concat(refVal[6].errors);
                    errors = vErrors.length;
                }
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.compiler', schemaPath: '#/properties/compiler/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.compiler.anyOf, parentSchema: validate.schema.properties.compiler, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.rules;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                if (!refVal[4](data1, (dataPath || '') + '.rules', data, 'rules', rootData)) {
                    if (vErrors === null) vErrors = refVal[4].errors;
                    else vErrors = vErrors.concat(refVal[4].errors);
                    errors = vErrors.length;
                }
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.rules', schemaPath: '#/properties/rules/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.rules.anyOf, parentSchema: validate.schema.properties.rules, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            if (data.test !== undefined) {
                var errs_1 = errors;
                var errs_2 = errors;
                if (!refVal[6](data.test, (dataPath || '') + '.test', data, 'test', rootData)) {
                    if (vErrors === null) vErrors = refVal[6].errors;
                    else vErrors = vErrors.concat(refVal[6].errors);
                    errors = vErrors.length;
                }
                var valid2 = errors === errs_2;
                var valid1 = errors === errs_1;
            }
            var data1 = data.use;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                if (!refVal[8](data1, (dataPath || '') + '.use', data, 'use', rootData)) {
                    if (vErrors === null) vErrors = refVal[8].errors;
                    else vErrors = vErrors.concat(refVal[8].errors);
                    errors = vErrors.length;
                }
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.use', schemaPath: '#/properties/use/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.use.anyOf, parentSchema: validate.schema.properties.use, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
        } else {
            var err = { keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.type, parentSchema: validate.schema, data: data };
            if (vErrors === null) vErrors = [err];
            else vErrors.push(err);
            errors++;
        }
View Code

規則:

1.必須為對象

2.exclude、include、test調用refVal6

3.loader為非空字符串

4.loaders調用refVal8

5.options必須為對象

6.rules調用refVal4

 

refVal6

var validate = (function(data, dataPath, parentData, parentDataProperty, rootData) {
        'use strict';
        validate.errors = null;
        return true;
    });
View Code

規則:

 

refVal8

var validate = (function(data, dataPath, parentData, parentDataProperty, rootData) {
        'use strict';
        validate.errors = null;
        return true;
    });
View Code

規則:

 

refVal10

if ((data && typeof data === "object" && !Array.isArray(data))) {
            var errs__0 = errors;
            var valid1 = true;
            for (var key0 in data) {
                var isAdditional0 = !(false || validate.schema.properties[key0]);
                if (isAdditional0) {
                    valid1 = false;
                    var err = { keyword: 'additionalProperties', dataPath: (dataPath || '') + "", schemaPath: '#/additionalProperties', params: { additionalProperty: '' + key0 + '' }, message: 'should NOT have additional properties', schema: false, parentSchema: validate.schema, data: data };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
            }
            var data1 = data.auxiliaryComment;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                if (typeof data1 !== "string") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.auxiliaryComment', schemaPath: '#/properties/auxiliaryComment/anyOf/0/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.auxiliaryComment.anyOf[0].type, parentSchema: validate.schema.properties.auxiliaryComment.anyOf[0], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var errs_2 = errors;
                    if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) {
                        var errs__2 = errors;
                        var valid3 = true;
                        for (var key2 in data1) {
                            var isAdditional2 = !(false || key2 == 'amd' || key2 == 'commonjs' || key2 == 'commonjs2' || key2 == 'root');
                            if (isAdditional2) {
                                valid3 = false;
                                var err = { keyword: 'additionalProperties', dataPath: (dataPath || '') + '.auxiliaryComment', schemaPath: '#/properties/auxiliaryComment/anyOf/1/additionalProperties', params: { additionalProperty: '' + key2 + '' }, message: 'should NOT have additional properties', schema: false, parentSchema: validate.schema.properties.auxiliaryComment.anyOf[1], data: data1 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                        }
                        var data2 = data1.amd;
                        if (data2 !== undefined) {
                            var errs_3 = errors;
                            if (typeof data2 !== "string") {
                                var err = { keyword: 'type', dataPath: (dataPath || '') + '.auxiliaryComment.amd', schemaPath: '#/properties/auxiliaryComment/anyOf/1/properties/amd/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.auxiliaryComment.anyOf[1].properties.amd.type, parentSchema: validate.schema.properties.auxiliaryComment.anyOf[1].properties.amd, data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                            var valid3 = errors === errs_3;
                        }
                        var data2 = data1.commonjs;
                        if (data2 !== undefined) {
                            var errs_3 = errors;
                            if (typeof data2 !== "string") {
                                var err = { keyword: 'type', dataPath: (dataPath || '') + '.auxiliaryComment.commonjs', schemaPath: '#/properties/auxiliaryComment/anyOf/1/properties/commonjs/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.auxiliaryComment.anyOf[1].properties.commonjs.type, parentSchema: validate.schema.properties.auxiliaryComment.anyOf[1].properties.commonjs, data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                            var valid3 = errors === errs_3;
                        }
                        var data2 = data1.commonjs2;
                        if (data2 !== undefined) {
                            var errs_3 = errors;
                            if (typeof data2 !== "string") {
                                var err = { keyword: 'type', dataPath: (dataPath || '') + '.auxiliaryComment.commonjs2', schemaPath: '#/properties/auxiliaryComment/anyOf/1/properties/commonjs2/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.auxiliaryComment.anyOf[1].properties.commonjs2.type, parentSchema: validate.schema.properties.auxiliaryComment.anyOf[1].properties.commonjs2, data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                            var valid3 = errors === errs_3;
                        }
                        var data2 = data1.root;
                        if (data2 !== undefined) {
                            var errs_3 = errors;
                            if (typeof data2 !== "string") {
                                var err = { keyword: 'type', dataPath: (dataPath || '') + '.auxiliaryComment.root', schemaPath: '#/properties/auxiliaryComment/anyOf/1/properties/root/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.auxiliaryComment.anyOf[1].properties.root.type, parentSchema: validate.schema.properties.auxiliaryComment.anyOf[1].properties.root, data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                            var valid3 = errors === errs_3;
                        }
                    } else {
                        var err = { keyword: 'type', dataPath: (dataPath || '') + '.auxiliaryComment', schemaPath: '#/properties/auxiliaryComment/anyOf/1/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.properties.auxiliaryComment.anyOf[1].type, parentSchema: validate.schema.properties.auxiliaryComment.anyOf[1], data: data1 };
                        if (vErrors === null) vErrors = [err];
                        else vErrors.push(err);
                        errors++;
                    }
                    var valid2 = errors === errs_2;
                    valid1 = valid1 || valid2;
                }
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.auxiliaryComment', schemaPath: '#/properties/auxiliaryComment/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.auxiliaryComment.anyOf, parentSchema: validate.schema.properties.auxiliaryComment, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.chunkFilename;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "string") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.chunkFilename', schemaPath: '#/properties/chunkFilename/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.chunkFilename.type, parentSchema: validate.schema.properties.chunkFilename, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.crossOriginLoading;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var schema1 = validate.schema.properties.crossOriginLoading.enum;
                var valid1;
                valid1 = false;
                for (var i1 = 0; i1 < schema1.length; i1++)
                    if (equal(data1, schema1[i1])) { valid1 = true; break; }
                if (!valid1) {
                    var err = { keyword: 'enum', dataPath: (dataPath || '') + '.crossOriginLoading', schemaPath: '#/properties/crossOriginLoading/enum', params: { allowedValues: schema1 }, message: 'should be equal to one of the allowed values', schema: validate.schema.properties.crossOriginLoading.enum, parentSchema: validate.schema.properties.crossOriginLoading, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.chunkLoadTimeout;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "number") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.chunkLoadTimeout', schemaPath: '#/properties/chunkLoadTimeout/type', params: { type: 'number' }, message: 'should be number', schema: validate.schema.properties.chunkLoadTimeout.type, parentSchema: validate.schema.properties.chunkLoadTimeout, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            if (data.devtoolFallbackModuleFilenameTemplate !== undefined) { var errs_1 = errors; var valid1 = errors === errs_1; }
            var data1 = data.devtoolLineToLine;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.devtoolLineToLine', schemaPath: '#/properties/devtoolLineToLine/anyOf/0/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.devtoolLineToLine.anyOf[0].type, parentSchema: validate.schema.properties.devtoolLineToLine.anyOf[0], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var errs_2 = errors;
                    if ((!data1 || typeof data1 !== "object" || Array.isArray(data1))) {
                        var err = { keyword: 'type', dataPath: (dataPath || '') + '.devtoolLineToLine', schemaPath: '#/properties/devtoolLineToLine/anyOf/1/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.properties.devtoolLineToLine.anyOf[1].type, parentSchema: validate.schema.properties.devtoolLineToLine.anyOf[1], data: data1 };
                        if (vErrors === null) vErrors = [err];
                        else vErrors.push(err);
                        errors++;
                    }
                    var valid2 = errors === errs_2;
                    valid1 = valid1 || valid2;
                }
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.devtoolLineToLine', schemaPath: '#/properties/devtoolLineToLine/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.devtoolLineToLine.anyOf, parentSchema: validate.schema.properties.devtoolLineToLine, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            if (data.devtoolModuleFilenameTemplate !== undefined) { var errs_1 = errors; var valid1 = errors === errs_1; }
            var data1 = data.filename;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "string") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.filename', schemaPath: '#/properties/filename/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.filename.type, parentSchema: validate.schema.properties.filename, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.hashDigest;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var schema1 = validate.schema.properties.hashDigest.enum;
                var valid1;
                valid1 = false;
                for (var i1 = 0; i1 < schema1.length; i1++)
                    if (equal(data1, schema1[i1])) { valid1 = true; break; }
                if (!valid1) {
                    var err = { keyword: 'enum', dataPath: (dataPath || '') + '.hashDigest', schemaPath: '#/properties/hashDigest/enum', params: { allowedValues: schema1 }, message: 'should be equal to one of the allowed values', schema: validate.schema.properties.hashDigest.enum, parentSchema: validate.schema.properties.hashDigest, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.hashDigestLength;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 === "number") {
                    if (data1 < 1 || data1 !== data1) {
                        var err = { keyword: 'minimum', dataPath: (dataPath || '') + '.hashDigestLength', schemaPath: '#/properties/hashDigestLength/minimum', params: { comparison: '>=', limit: 1, exclusive: false }, message: 'should be >= 1', schema: 1, parentSchema: validate.schema.properties.hashDigestLength, data: data1 };
                        if (vErrors === null) vErrors = [err];
                        else vErrors.push(err);
                        errors++;
                    }
                } else {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.hashDigestLength', schemaPath: '#/properties/hashDigestLength/type', params: { type: 'number' }, message: 'should be number', schema: validate.schema.properties.hashDigestLength.type, parentSchema: validate.schema.properties.hashDigestLength, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.hashFunction;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 === "string") {
                    if (ucs2length(data1) < 1) {
                        var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.hashFunction', schemaPath: '#/properties/hashFunction/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: validate.schema.properties.hashFunction, data: data1 };
                        if (vErrors === null) vErrors = [err];
                        else vErrors.push(err);
                        errors++;
                    }
                } else {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.hashFunction', schemaPath: '#/properties/hashFunction/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.hashFunction.type, parentSchema: validate.schema.properties.hashFunction, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.hashSalt;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 === "string") {
                    if (ucs2length(data1) < 1) {
                        var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.hashSalt', schemaPath: '#/properties/hashSalt/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: validate.schema.properties.hashSalt, data: data1 };
                        if (vErrors === null) vErrors = [err];
                        else vErrors.push(err);
                        errors++;
                    }
                } else {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.hashSalt', schemaPath: '#/properties/hashSalt/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.hashSalt.type, parentSchema: validate.schema.properties.hashSalt, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.hotUpdateChunkFilename;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "string") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.hotUpdateChunkFilename', schemaPath: '#/properties/hotUpdateChunkFilename/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.hotUpdateChunkFilename.type, parentSchema: validate.schema.properties.hotUpdateChunkFilename, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.hotUpdateFunction;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "string") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.hotUpdateFunction', schemaPath: '#/properties/hotUpdateFunction/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.hotUpdateFunction.type, parentSchema: validate.schema.properties.hotUpdateFunction, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.hotUpdateMainFilename;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "string") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.hotUpdateMainFilename', schemaPath: '#/properties/hotUpdateMainFilename/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.hotUpdateMainFilename.type, parentSchema: validate.schema.properties.hotUpdateMainFilename, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.jsonpFunction;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "string") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.jsonpFunction', schemaPath: '#/properties/jsonpFunction/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.jsonpFunction.type, parentSchema: validate.schema.properties.jsonpFunction, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.library;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                if (typeof data1 !== "string") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.library', schemaPath: '#/properties/library/anyOf/0/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.library.anyOf[0].type, parentSchema: validate.schema.properties.library.anyOf[0], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var errs_2 = errors;
                    if (Array.isArray(data1)) {
                        var errs__2 = errors;
                        var valid2;
                        for (var i2 = 0; i2 < data1.length; i2++) {
                            var data2 = data1[i2];
                            var errs_3 = errors;
                            if (typeof data2 !== "string") {
                                var err = { keyword: 'type', dataPath: (dataPath || '') + '.library[' + i2 + ']', schemaPath: '#/properties/library/anyOf/1/items/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.library.anyOf[1].items.type, parentSchema: validate.schema.properties.library.anyOf[1].items, data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                            var valid3 = errors === errs_3;
                        }
                    } else {
                        var err = { keyword: 'type', dataPath: (dataPath || '') + '.library', schemaPath: '#/properties/library/anyOf/1/type', params: { type: 'array' }, message: 'should be array', schema: validate.schema.properties.library.anyOf[1].type, parentSchema: validate.schema.properties.library.anyOf[1], data: data1 };
                        if (vErrors === null) vErrors = [err];
                        else vErrors.push(err);
                        errors++;
                    }
                    var valid2 = errors === errs_2;
                    valid1 = valid1 || valid2;
                    if (!valid1) {
                        var errs_2 = errors;
                        if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) {
                            var errs__2 = errors;
                            var valid3 = true;
                            for (var key2 in data1) {
                                var isAdditional2 = !(false || key2 == 'root' || key2 == 'amd' || key2 == 'commonjs');
                                if (isAdditional2) {
                                    valid3 = false;
                                    var err = { keyword: 'additionalProperties', dataPath: (dataPath || '') + '.library', schemaPath: '#/properties/library/anyOf/2/additionalProperties', params: { additionalProperty: '' + key2 + '' }, message: 'should NOT have additional properties', schema: false, parentSchema: validate.schema.properties.library.anyOf[2], data: data1 };
                                    if (vErrors === null) vErrors = [err];
                                    else vErrors.push(err);
                                    errors++;
                                }
                            }
                            var data2 = data1.root;
                            if (data2 !== undefined) {
                                var errs_3 = errors;
                                if (typeof data2 !== "string") {
                                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.library.root', schemaPath: '#/properties/library/anyOf/2/properties/root/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.library.anyOf[2].properties.root.type, parentSchema: validate.schema.properties.library.anyOf[2].properties.root, data: data2 };
                                    if (vErrors === null) vErrors = [err];
                                    else vErrors.push(err);
                                    errors++;
                                }
                                var valid3 = errors === errs_3;
                            }
                            var data2 = data1.amd;
                            if (data2 !== undefined) {
                                var errs_3 = errors;
                                if (typeof data2 !== "string") {
                                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.library.amd', schemaPath: '#/properties/library/anyOf/2/properties/amd/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.library.anyOf[2].properties.amd.type, parentSchema: validate.schema.properties.library.anyOf[2].properties.amd, data: data2 };
                                    if (vErrors === null) vErrors = [err];
                                    else vErrors.push(err);
                                    errors++;
                                }
                                var valid3 = errors === errs_3;
                            }
                            var data2 = data1.commonjs;
                            if (data2 !== undefined) {
                                var errs_3 = errors;
                                if (typeof data2 !== "string") {
                                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.library.commonjs', schemaPath: '#/properties/library/anyOf/2/properties/commonjs/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.library.anyOf[2].properties.commonjs.type, parentSchema: validate.schema.properties.library.anyOf[2].properties.commonjs, data: data2 };
                                    if (vErrors === null) vErrors = [err];
                                    else vErrors.push(err);
                                    errors++;
                                }
                                var valid3 = errors === errs_3;
                            }
                        } else {
                            var err = { keyword: 'type', dataPath: (dataPath || '') + '.library', schemaPath: '#/properties/library/anyOf/2/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.properties.library.anyOf[2].type, parentSchema: validate.schema.properties.library.anyOf[2], data: data1 };
                            if (vErrors === null) vErrors = [err];
                            else vErrors.push(err);
                            errors++;
                        }
                        var valid2 = errors === errs_2;
                        valid1 = valid1 || valid2;
                    }
                }
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.library', schemaPath: '#/properties/library/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.library.anyOf, parentSchema: validate.schema.properties.library, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.libraryTarget;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var schema1 = validate.schema.properties.libraryTarget.enum;
                var valid1;
                valid1 = false;
                for (var i1 = 0; i1 < schema1.length; i1++)
                    if (equal(data1, schema1[i1])) { valid1 = true; break; }
                if (!valid1) {
                    var err = { keyword: 'enum', dataPath: (dataPath || '') + '.libraryTarget', schemaPath: '#/properties/libraryTarget/enum', params: { allowedValues: schema1 }, message: 'should be equal to one of the allowed values', schema: validate.schema.properties.libraryTarget.enum, parentSchema: validate.schema.properties.libraryTarget, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.libraryExport;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                if (typeof data1 !== "string") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.libraryExport', schemaPath: '#/properties/libraryExport/anyOf/0/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.libraryExport.anyOf[0].type, parentSchema: validate.schema.properties.libraryExport.anyOf[0], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var errs_2 = errors;
                    var errs_3 = errors;
                    if (Array.isArray(data1)) {
                        var errs__3 = errors;
                        var valid3;
                        for (var i3 = 0; i3 < data1.length; i3++) {
                            var data2 = data1[i3];
                            var errs_4 = errors;
                            if (typeof data2 === "string") {
                                if (ucs2length(data2) < 1) {
                                    var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.libraryExport[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal11.items, data: data2 };
                                    if (vErrors === null) vErrors = [err];
                                    else vErrors.push(err);
                                    errors++;
                                }
                            } else {
                                var err = { keyword: 'type', dataPath: (dataPath || '') + '.libraryExport[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal11.items.type, parentSchema: refVal11.items, data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                            var valid4 = errors === errs_4;
                        }
                    } else {
                        var err = { keyword: 'type', dataPath: (dataPath || '') + '.libraryExport', schemaPath: '#/definitions/common.arrayOfStringValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal11.type, parentSchema: refVal11, data: data1 };
                        if (vErrors === null) vErrors = [err];
                        else vErrors.push(err);
                        errors++;
                    }
                    var valid3 = errors === errs_3;
                    var valid2 = errors === errs_2;
                    valid1 = valid1 || valid2;
                }
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.libraryExport', schemaPath: '#/properties/libraryExport/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.libraryExport.anyOf, parentSchema: validate.schema.properties.libraryExport, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.path;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "string") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.path', schemaPath: '#/properties/path/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.path.type, parentSchema: validate.schema.properties.path, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.pathinfo;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.pathinfo', schemaPath: '#/properties/pathinfo/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.pathinfo.type, parentSchema: validate.schema.properties.pathinfo, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.publicPath;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "string") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.publicPath', schemaPath: '#/properties/publicPath/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.publicPath.type, parentSchema: validate.schema.properties.publicPath, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.sourceMapFilename;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "string") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.sourceMapFilename', schemaPath: '#/properties/sourceMapFilename/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.sourceMapFilename.type, parentSchema: validate.schema.properties.sourceMapFilename, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.sourcePrefix;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "string") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.sourcePrefix', schemaPath: '#/properties/sourcePrefix/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.sourcePrefix.type, parentSchema: validate.schema.properties.sourcePrefix, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.strictModuleExceptionHandling;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.strictModuleExceptionHandling', schemaPath: '#/properties/strictModuleExceptionHandling/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.strictModuleExceptionHandling.type, parentSchema: validate.schema.properties.strictModuleExceptionHandling, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.umdNamedDefine;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.umdNamedDefine', schemaPath: '#/properties/umdNamedDefine/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.umdNamedDefine.type, parentSchema: validate.schema.properties.umdNamedDefine, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
        } else {
            var err = { keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.type, parentSchema: validate.schema, data: data };
            if (vErrors === null) vErrors = [err];
            else vErrors.push(err);
            errors++;
        }
View Code

規則:

1.額外鍵檢測

2.chunkFilename、filename、path、publicPath必須為字符串

3.crossOriginLoading必須是false、"anonymous"、"use-credentials"之一

4.chunkLoadTimeout必須是數字

 

refVal12

if ((data && typeof data === "object" && !Array.isArray(data))) {
            var errs__0 = errors;
            var valid1 = true;
            for (var key0 in data) {
                var isAdditional0 = !(false || validate.schema.properties[key0]);
                if (isAdditional0) {
                    valid1 = false;
                    var err = { keyword: 'additionalProperties', dataPath: (dataPath || '') + "", schemaPath: '#/additionalProperties', params: { additionalProperty: '' + key0 + '' }, message: 'should NOT have additional properties', schema: false, parentSchema: validate.schema, data: data };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
            }
            var data1 = data.alias;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) {
                    var errs__2 = errors;
                    var valid3 = true;
                    for (var key2 in data1) {
                        var data2 = data1[key2];
                        var errs_3 = errors;
                        if (typeof data2 !== "string") {
                            var err = { keyword: 'type', dataPath: (dataPath || '') + '.alias[\'' + key2 + '\']', schemaPath: '#/properties/alias/anyOf/0/additionalProperties/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.alias.anyOf[0].additionalProperties.type, parentSchema: validate.schema.properties.alias.anyOf[0].additionalProperties, data: data2 };
                            if (vErrors === null) vErrors = [err];
                            else vErrors.push(err);
                            errors++;
                        }
                        var valid3 = errors === errs_3;
                    }
                } else {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.alias', schemaPath: '#/properties/alias/anyOf/0/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.properties.alias.anyOf[0].type, parentSchema: validate.schema.properties.alias.anyOf[0], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var errs_2 = errors;
                    if (Array.isArray(data1)) {
                        var errs__2 = errors;
                        var valid2;
                        for (var i2 = 0; i2 < data1.length; i2++) {
                            var data2 = data1[i2];
                            var errs_3 = errors;
                            if ((data2 && typeof data2 === "object" && !Array.isArray(data2))) {
                                var errs__3 = errors;
                                var valid4 = true;
                                for (var key3 in data2) {
                                    var isAdditional3 = !(false || key3 == 'alias' || key3 == 'name' || key3 == 'onlyModule');
                                    if (isAdditional3) {
                                        valid4 = false;
                                        var err = { keyword: 'additionalProperties', dataPath: (dataPath || '') + '.alias[' + i2 + ']', schemaPath: '#/properties/alias/anyOf/1/items/additionalProperties', params: { additionalProperty: '' + key3 + '' }, message: 'should NOT have additional properties', schema: false, parentSchema: validate.schema.properties.alias.anyOf[1].items, data: data2 };
                                        if (vErrors === null) vErrors = [err];
                                        else vErrors.push(err);
                                        errors++;
                                    }
                                }
                                var data3 = data2.alias;
                                if (data3 !== undefined) {
                                    var errs_4 = errors;
                                    if (typeof data3 !== "string") {
                                        var err = { keyword: 'type', dataPath: (dataPath || '') + '.alias[' + i2 + '].alias', schemaPath: '#/properties/alias/anyOf/1/items/properties/alias/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.alias.anyOf[1].items.properties.alias.type, parentSchema: validate.schema.properties.alias.anyOf[1].items.properties.alias, data: data3 };
                                        if (vErrors === null) vErrors = [err];
                                        else vErrors.push(err);
                                        errors++;
                                    }
                                    var valid4 = errors === errs_4;
                                }
                                var data3 = data2.name;
                                if (data3 !== undefined) {
                                    var errs_4 = errors;
                                    if (typeof data3 !== "string") {
                                        var err = { keyword: 'type', dataPath: (dataPath || '') + '.alias[' + i2 + '].name', schemaPath: '#/properties/alias/anyOf/1/items/properties/name/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.alias.anyOf[1].items.properties.name.type, parentSchema: validate.schema.properties.alias.anyOf[1].items.properties.name, data: data3 };
                                        if (vErrors === null) vErrors = [err];
                                        else vErrors.push(err);
                                        errors++;
                                    }
                                    var valid4 = errors === errs_4;
                                }
                                var data3 = data2.onlyModule;
                                if (data3 !== undefined) {
                                    var errs_4 = errors;
                                    if (typeof data3 !== "boolean") {
                                        var err = { keyword: 'type', dataPath: (dataPath || '') + '.alias[' + i2 + '].onlyModule', schemaPath: '#/properties/alias/anyOf/1/items/properties/onlyModule/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.alias.anyOf[1].items.properties.onlyModule.type, parentSchema: validate.schema.properties.alias.anyOf[1].items.properties.onlyModule, data: data3 };
                                        if (vErrors === null) vErrors = [err];
                                        else vErrors.push(err);
                                        errors++;
                                    }
                                    var valid4 = errors === errs_4;
                                }
                            } else {
                                var err = { keyword: 'type', dataPath: (dataPath || '') + '.alias[' + i2 + ']', schemaPath: '#/properties/alias/anyOf/1/items/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.properties.alias.anyOf[1].items.type, parentSchema: validate.schema.properties.alias.anyOf[1].items, data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                            var valid3 = errors === errs_3;
                        }
                    } else {
                        var err = { keyword: 'type', dataPath: (dataPath || '') + '.alias', schemaPath: '#/properties/alias/anyOf/1/type', params: { type: 'array' }, message: 'should be array', schema: validate.schema.properties.alias.anyOf[1].type, parentSchema: validate.schema.properties.alias.anyOf[1], data: data1 };
                        if (vErrors === null) vErrors = [err];
                        else vErrors.push(err);
                        errors++;
                    }
                    var valid2 = errors === errs_2;
                    valid1 = valid1 || valid2;
                }
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.alias', schemaPath: '#/properties/alias/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.alias.anyOf, parentSchema: validate.schema.properties.alias, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.aliasFields;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                var errs_3 = errors;
                if (Array.isArray(data1)) {
                    var errs__3 = errors;
                    var valid3;
                    for (var i3 = 0; i3 < data1.length; i3++) {
                        var data2 = data1[i3];
                        var errs_4 = errors;
                        var errs__4 = errors;
                        var valid4 = false;
                        var errs_5 = errors;
                        if (typeof data2 === "string") {
                            if (ucs2length(data2) < 1) {
                                var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.aliasFields[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/0/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal13.items.anyOf[0], data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                        } else {
                            var err = { keyword: 'type', dataPath: (dataPath || '') + '.aliasFields[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/0/type', params: { type: 'string' }, message: 'should be string', schema: refVal13.items.anyOf[0].type, parentSchema: refVal13.items.anyOf[0], data: data2 };
                            if (vErrors === null) vErrors = [err];
                            else vErrors.push(err);
                            errors++;
                        }
                        var valid5 = errors === errs_5;
                        valid4 = valid4 || valid5;
                        if (!valid4) {
                            var errs_5 = errors;
                            if (Array.isArray(data2)) {
                                var errs__5 = errors;
                                var valid5;
                                for (var i5 = 0; i5 < data2.length; i5++) {
                                    var data3 = data2[i5];
                                    var errs_6 = errors;
                                    if (typeof data3 === "string") {
                                        if (ucs2length(data3) < 1) {
                                            var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.aliasFields[' + i3 + '][' + i5 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/1/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal13.items.anyOf[1].items, data: data3 };
                                            if (vErrors === null) vErrors = [err];
                                            else vErrors.push(err);
                                            errors++;
                                        }
                                    } else {
                                        var err = { keyword: 'type', dataPath: (dataPath || '') + '.aliasFields[' + i3 + '][' + i5 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/1/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal13.items.anyOf[1].items.type, parentSchema: refVal13.items.anyOf[1].items, data: data3 };
                                        if (vErrors === null) vErrors = [err];
                                        else vErrors.push(err);
                                        errors++;
                                    }
                                    var valid6 = errors === errs_6;
                                }
                            } else {
                                var err = { keyword: 'type', dataPath: (dataPath || '') + '.aliasFields[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/1/type', params: { type: 'array' }, message: 'should be array', schema: refVal13.items.anyOf[1].type, parentSchema: refVal13.items.anyOf[1], data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                            var valid5 = errors === errs_5;
                            valid4 = valid4 || valid5;
                        }
                        if (!valid4) {
                            var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.aliasFields[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf', params: {}, message: 'should match some schema in anyOf', schema: refVal13.items.anyOf, parentSchema: refVal13.items, data: data2 };
                            if (vErrors === null) vErrors = [err];
                            else vErrors.push(err);
                            errors++;
                        } else {
                            errors = errs__4;
                            if (vErrors !== null) {
                                if (errs__4) vErrors.length = errs__4;
                                else vErrors = null;
                            }
                        }
                        var valid4 = errors === errs_4;
                    }
                } else {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.aliasFields', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal13.type, parentSchema: refVal13, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid3 = errors === errs_3;
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.aliasFields', schemaPath: '#/properties/aliasFields/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.aliasFields.anyOf, parentSchema: validate.schema.properties.aliasFields, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.cacheWithContext;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.cacheWithContext', schemaPath: '#/properties/cacheWithContext/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.cacheWithContext.type, parentSchema: validate.schema.properties.cacheWithContext, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.descriptionFiles;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                var errs_3 = errors;
                if (Array.isArray(data1)) {
                    var errs__3 = errors;
                    var valid3;
                    for (var i3 = 0; i3 < data1.length; i3++) {
                        var data2 = data1[i3];
                        var errs_4 = errors;
                        if (typeof data2 === "string") {
                            if (ucs2length(data2) < 1) {
                                var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.descriptionFiles[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal[11].items, data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                        } else {
                            var err = { keyword: 'type', dataPath: (dataPath || '') + '.descriptionFiles[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal[11].items.type, parentSchema: refVal[11].items, data: data2 };
                            if (vErrors === null) vErrors = [err];
                            else vErrors.push(err);
                            errors++;
                        }
                        var valid4 = errors === errs_4;
                    }
                } else {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.descriptionFiles', schemaPath: '#/definitions/common.arrayOfStringValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal[11].type, parentSchema: refVal[11], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid3 = errors === errs_3;
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.descriptionFiles', schemaPath: '#/properties/descriptionFiles/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.descriptionFiles.anyOf, parentSchema: validate.schema.properties.descriptionFiles, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.enforceExtension;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.enforceExtension', schemaPath: '#/properties/enforceExtension/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.enforceExtension.type, parentSchema: validate.schema.properties.enforceExtension, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.enforceModuleExtension;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.enforceModuleExtension', schemaPath: '#/properties/enforceModuleExtension/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.enforceModuleExtension.type, parentSchema: validate.schema.properties.enforceModuleExtension, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.extensions;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                var errs_3 = errors;
                if (Array.isArray(data1)) {
                    var errs__3 = errors;
                    var valid3;
                    for (var i3 = 0; i3 < data1.length; i3++) {
                        var data2 = data1[i3];
                        var errs_4 = errors;
                        if (typeof data2 === "string") {
                            if (ucs2length(data2) < 1) {
                                var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.extensions[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal[11].items, data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                        } else {
                            var err = { keyword: 'type', dataPath: (dataPath || '') + '.extensions[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal[11].items.type, parentSchema: refVal[11].items, data: data2 };
                            if (vErrors === null) vErrors = [err];
                            else vErrors.push(err);
                            errors++;
                        }
                        var valid4 = errors === errs_4;
                    }
                } else {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.extensions', schemaPath: '#/definitions/common.arrayOfStringValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal[11].type, parentSchema: refVal[11], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid3 = errors === errs_3;
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.extensions', schemaPath: '#/properties/extensions/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.extensions.anyOf, parentSchema: validate.schema.properties.extensions, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.mainFields;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                var errs_3 = errors;
                if (Array.isArray(data1)) {
                    var errs__3 = errors;
                    var valid3;
                    for (var i3 = 0; i3 < data1.length; i3++) {
                        var data2 = data1[i3];
                        var errs_4 = errors;
                        var errs__4 = errors;
                        var valid4 = false;
                        var errs_5 = errors;
                        if (typeof data2 === "string") {
                            if (ucs2length(data2) < 1) {
                                var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.mainFields[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/0/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal[13].items.anyOf[0], data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                        } else {
                            var err = { keyword: 'type', dataPath: (dataPath || '') + '.mainFields[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/0/type', params: { type: 'string' }, message: 'should be string', schema: refVal[13].items.anyOf[0].type, parentSchema: refVal[13].items.anyOf[0], data: data2 };
                            if (vErrors === null) vErrors = [err];
                            else vErrors.push(err);
                            errors++;
                        }
                        var valid5 = errors === errs_5;
                        valid4 = valid4 || valid5;
                        if (!valid4) {
                            var errs_5 = errors;
                            if (Array.isArray(data2)) {
                                var errs__5 = errors;
                                var valid5;
                                for (var i5 = 0; i5 < data2.length; i5++) {
                                    var data3 = data2[i5];
                                    var errs_6 = errors;
                                    if (typeof data3 === "string") {
                                        if (ucs2length(data3) < 1) {
                                            var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.mainFields[' + i3 + '][' + i5 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/1/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal[13].items.anyOf[1].items, data: data3 };
                                            if (vErrors === null) vErrors = [err];
                                            else vErrors.push(err);
                                            errors++;
                                        }
                                    } else {
                                        var err = { keyword: 'type', dataPath: (dataPath || '') + '.mainFields[' + i3 + '][' + i5 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/1/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal[13].items.anyOf[1].items.type, parentSchema: refVal[13].items.anyOf[1].items, data: data3 };
                                        if (vErrors === null) vErrors = [err];
                                        else vErrors.push(err);
                                        errors++;
                                    }
                                    var valid6 = errors === errs_6;
                                }
                            } else {
                                var err = { keyword: 'type', dataPath: (dataPath || '') + '.mainFields[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/1/type', params: { type: 'array' }, message: 'should be array', schema: refVal[13].items.anyOf[1].type, parentSchema: refVal[13].items.anyOf[1], data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                            var valid5 = errors === errs_5;
                            valid4 = valid4 || valid5;
                        }
                        if (!valid4) {
                            var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.mainFields[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf', params: {}, message: 'should match some schema in anyOf', schema: refVal[13].items.anyOf, parentSchema: refVal[13].items, data: data2 };
                            if (vErrors === null) vErrors = [err];
                            else vErrors.push(err);
                            errors++;
                        } else {
                            errors = errs__4;
                            if (vErrors !== null) {
                                if (errs__4) vErrors.length = errs__4;
                                else vErrors = null;
                            }
                        }
                        var valid4 = errors === errs_4;
                    }
                } else {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.mainFields', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal[13].type, parentSchema: refVal[13], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid3 = errors === errs_3;
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.mainFields', schemaPath: '#/properties/mainFields/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.mainFields.anyOf, parentSchema: validate.schema.properties.mainFields, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.mainFiles;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                var errs_3 = errors;
                if (Array.isArray(data1)) {
                    var errs__3 = errors;
                    var valid3;
                    for (var i3 = 0; i3 < data1.length; i3++) {
                        var data2 = data1[i3];
                        var errs_4 = errors;
                        if (typeof data2 === "string") {
                            if (ucs2length(data2) < 1) {
                                var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.mainFiles[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal[11].items, data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                        } else {
                            var err = { keyword: 'type', dataPath: (dataPath || '') + '.mainFiles[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal[11].items.type, parentSchema: refVal[11].items, data: data2 };
                            if (vErrors === null) vErrors = [err];
                            else vErrors.push(err);
                            errors++;
                        }
                        var valid4 = errors === errs_4;
                    }
                } else {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.mainFiles', schemaPath: '#/definitions/common.arrayOfStringValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal[11].type, parentSchema: refVal[11], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid3 = errors === errs_3;
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.mainFiles', schemaPath: '#/properties/mainFiles/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.mainFiles.anyOf, parentSchema: validate.schema.properties.mainFiles, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.moduleExtensions;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                var errs_3 = errors;
                if (Array.isArray(data1)) {
                    var errs__3 = errors;
                    var valid3;
                    for (var i3 = 0; i3 < data1.length; i3++) {
                        var data2 = data1[i3];
                        var errs_4 = errors;
                        if (typeof data2 === "string") {
                            if (ucs2length(data2) < 1) {
                                var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.moduleExtensions[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal[11].items, data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                        } else {
                            var err = { keyword: 'type', dataPath: (dataPath || '') + '.moduleExtensions[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal[11].items.type, parentSchema: refVal[11].items, data: data2 };
                            if (vErrors === null) vErrors = [err];
                            else vErrors.push(err);
                            errors++;
                        }
                        var valid4 = errors === errs_4;
                    }
                } else {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.moduleExtensions', schemaPath: '#/definitions/common.arrayOfStringValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal[11].type, parentSchema: refVal[11], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid3 = errors === errs_3;
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.moduleExtensions', schemaPath: '#/properties/moduleExtensions/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.moduleExtensions.anyOf, parentSchema: validate.schema.properties.moduleExtensions, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.modules;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                var errs_3 = errors;
                if (Array.isArray(data1)) {
                    var errs__3 = errors;
                    var valid3;
                    for (var i3 = 0; i3 < data1.length; i3++) {
                        var data2 = data1[i3];
                        var errs_4 = errors;
                        if (typeof data2 === "string") {
                            if (ucs2length(data2) < 1) {
                                var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.modules[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal[11].items, data: data2 };
                                if (vErrors === null) vErrors = [err];
                                else vErrors.push(err);
                                errors++;
                            }
                        } else {
                            var err = { keyword: 'type', dataPath: (dataPath || '') + '.modules[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal[11].items.type, parentSchema: refVal[11].items, data: data2 };
                            if (vErrors === null) vErrors = [err];
                            else vErrors.push(err);
                            errors++;
                        }
                        var valid4 = errors === errs_4;
                    }
                } else {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.modules', schemaPath: '#/definitions/common.arrayOfStringValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal[11].type, parentSchema: refVal[11], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid3 = errors === errs_3;
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.modules', schemaPath: '#/properties/modules/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.modules.anyOf, parentSchema: validate.schema.properties.modules, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.plugins;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (!Array.isArray(data1)) {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.plugins', schemaPath: '#/properties/plugins/type', params: { type: 'array' }, message: 'should be array', schema: validate.schema.properties.plugins.type, parentSchema: validate.schema.properties.plugins, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.symlinks;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.symlinks', schemaPath: '#/properties/symlinks/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.symlinks.type, parentSchema: validate.schema.properties.symlinks, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.unsafeCache;
            if (data1 !== undefined) {
                var errs_1 = errors;
                var errs__1 = errors;
                var valid1 = false;
                var errs_2 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.unsafeCache', schemaPath: '#/properties/unsafeCache/anyOf/0/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.unsafeCache.anyOf[0].type, parentSchema: validate.schema.properties.unsafeCache.anyOf[0], data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {
                    var errs_2 = errors;
                    if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) { var errs__2 = errors; var valid3 = true; } else {
                        var err = { keyword: 'type', dataPath: (dataPath || '') + '.unsafeCache', schemaPath: '#/properties/unsafeCache/anyOf/1/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.properties.unsafeCache.anyOf[1].type, parentSchema: validate.schema.properties.unsafeCache.anyOf[1], data: data1 };
                        if (vErrors === null) vErrors = [err];
                        else vErrors.push(err);
                        errors++;
                    }
                    var valid2 = errors === errs_2;
                    valid1 = valid1 || valid2;
                }
                if (!valid1) {
                    var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.unsafeCache', schemaPath: '#/properties/unsafeCache/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.unsafeCache.anyOf, parentSchema: validate.schema.properties.unsafeCache, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                } else {
                    errors = errs__1;
                    if (vErrors !== null) {
                        if (errs__1) vErrors.length = errs__1;
                        else vErrors = null;
                    }
                }
                var valid1 = errors === errs_1;
            }
            var data1 = data.useSyncFileSystemCalls;
            if (data1 !== undefined) {
                var errs_1 = errors;
                if (typeof data1 !== "boolean") {
                    var err = { keyword: 'type', dataPath: (dataPath || '') + '.useSyncFileSystemCalls', schemaPath: '#/properties/useSyncFileSystemCalls/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.useSyncFileSystemCalls.type, parentSchema: validate.schema.properties.useSyncFileSystemCalls, data: data1 };
                    if (vErrors === null) vErrors = [err];
                    else vErrors.push(err);
                    errors++;
                }
                var valid1 = errors === errs_1;
            }
        } else {
            var err = { keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.type, parentSchema: validate.schema, data: data };
            if (vErrors === null) vErrors = [err];
            else vErrors.push(err);
            errors++;
        }
View Code

規則:

1.必須是對象

2.額外鍵檢測

3.alias可以是對象、數組

4.alias為數組時,數組元素必須是對象,且鍵必須為alias、name、onlyModule之一

5.鍵為alias、name的值必須是字符串,鍵為onlyModule的值必須為布爾值

6.extensions必須是數組,數組元素必須是非空字符串

 

  由於可選參數過於龐大,所以的代碼只展示常用的屬性校驗,剔除大量陌生屬性,不然實在是太長了!!!!!!!!

 

1、rootObject

  首先是根對象的檢測:

// 對象判斷
if ((data && typeof data === "object" && !Array.isArray(data))) {
    var errs__0 = errors;
    var valid1 = true;
    // 遍歷key
    for (var key0 in data) {
        // 這里檢測屬性中是否有檢測范圍外的鍵
        var isAdditional0 = !(false || validate.schema.properties[key0]);
        if (isAdditional0) {
            valid1 = false;
            // 生成報錯信息
            var err = { keyword: 'additionalProperties', dataPath: (dataPath || '') + 
            "", schemaPath: '#/additionalProperties', params: { additionalProperty: '' + 
            key0 + 
            '' }, message: 'should NOT have additional properties', schema: false, parentSchema: validate.schema, data: data };
            // 第一次產生錯誤時初始化vErrors為數組
            if (vErrors === null) vErrors = [err];
            else vErrors.push(err);
            errors++;
        }
    }
} else{ /*添加錯誤*/ }

  這里還有一個validate.schema.properties對象,通過翻源碼找到了定義:

  

  一句話概括就是,在根對象中會檢測是否有多余的鍵,可以測試一下:

const validate = ajv.compile(json);
const valid = validate({
    "unexpectedKey":0,
});
console.log(validate.errors);

  輸出內容如下:

  

 

2、devServer

var data1 = data.devServer;
// 存在鍵就繼續檢測
// 由於是非必須項 所以沒有也不報錯
if (data1 !== undefined) {
    var errs_1 = errors;
    // 檢測是是對象
    if ((!data1 || typeof data1 !== "object" || Array.isArray(data1))) {
        // 生成報錯信息
    }
    // 如果檢測后總錯誤數量不變 說明通過
    var valid1 = errors === errs_1;
}

  一句話概括:如果存在該鍵則必須為對象。

 

3、devtool

var data1 = data.devtool;
if (data1 !== undefined) {
    var valid1 = false;
    // 標記初始值
    var errs_1 = errors;
    // 用於記錄錯誤
    var errs__1 = errors;
    var errs_2 = errors;
    // 判斷字符串
    if (typeof data1 !== "string") { /*添加錯誤*/ }
    var valid2 = errors === errs_2;
    valid1 = valid1 || valid2;
    // 如果上面報錯進入這里
    if (!valid1) {
        var errs_2 = errors;
        // 獲取枚舉數組
        var schema2 = validate.schema.properties.devtool.anyOf[1].enum;
        var valid2;
        valid2 = false;
        // 遍歷判斷是否匹配元素
        for (var i2 = 0; i2 < schema2.length; i2++)
            if (equal(data1, schema2[i2])) { valid2 = true; break; }
        if (!valid2) { /*添加錯誤*/ }
        var valid2 = errors === errs_2;
        valid1 = valid1 || valid2;
    }
    // 即非字符串也不是枚舉數組元素
    if (!valid1) { /*添加錯誤*/ } 
    // 如果有一個符合就回滾錯誤數量 驗證通過
    else {
        errors = errs__1;
        if (vErrors !== null) {
            if (errs__1) vErrors.length = errs__1;
            else vErrors = null;
        }
    }
    var valid1 = errors === errs_1;
}

  其中枚舉數組如圖:  

  一句話概括:devtool可以為字符串或者false。

 

4、entry

var data1 = data.entry;
// 檢測鍵是否存在
if (data1 === undefined) { /*添加錯誤*/ } 
else {
    var errs_1 = errors;
    var errs__1 = errors;
    var valid1 = false;
    var errs_2 = errors;
    // refVal1
    if (!refVal1(data1, (dataPath || '') + '.entry', data, 'entry', rootData)) { /*添加錯誤*/ }
    var valid2 = errors === errs_2;
    valid1 = valid1 || valid2;
    if (!valid1) { /*添加錯誤*/ }
    // 通過
    else {
        errors = errs__1;
        if (vErrors !== null) {
            if (errs__1) vErrors.length = errs__1;
            else vErrors = null;
        }
    }
    var valid1 = errors === errs_1;
}

  調用了refVal1校驗器,不願意看上面的代碼可以直接看規則。

 

5、module => refVal3

 

6、output => refVal10

 

7、plugins

var data1 = data.plugins;
if (data1 !== undefined) {
    var errs_1 = errors;
    // 必須是數組
    if (!Array.isArray(data1)) { /**/ }
    var valid1 = errors === errs_1;
}

 

8、resolve => refVal12

 

  真是又臭又長,再返回validate校驗函數后,會進行校驗 :

    const valid = validate(options);
    return valid ? [] : filterErrors(validate.errors);

  根據是否有錯誤返回true或false,由於在檢測的時候已經對錯誤進行了收集,所以可以直接從 validate.errors 獲取,這里的過濾就不看了,惡心的不行。

  然后會返回到webpack主函數:

    const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, options);
    if (webpackOptionsValidationErrors.length) {
        throw new WebpackOptionsValidationError(webpackOptionsValidationErrors);
    }

  根據 webpackOptionsValidationErrors 的長度來判斷是否有錯誤,有錯則拋出並中止編譯。

 

完事!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM