Code coverage report for lib/util/invariant.js

Statements: 100% (11 / 11)      Branches: 100% (4 / 4)      Functions: 100% (2 / 2)      Lines: 100% (11 / 11)      Ignored: none     

All files » lib/util/ » invariant.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62                                                                1   91 76     15 1           14 14   14     2     14           1  
/**
 * @file invariant
 * @author Leon(leon@outlook.com)
 */
 
/**
 * Use invariant() to assert state which your program assumes to be true.
 *
 * Provide sprintf-style format (only %s is supported) and arguments
 * to provide information about what broke and what you were
 * expecting.
 *
 * The invariant message will be stripped in production, but the invariant
 * will remain to ensure logic does not differ in production.
 */
 
/* eslint-disable max-params */
 
/**
 * 断言
 *
 * @ignore
 *
 * @param {boolean}     condition 断言条件
 * @param {string}      format 断言失败消息模板
 * @param {*} a 断言失败消息数据
 * @param {*} b 断言失败消息数据
 * @param {*} c 断言失败消息数据
 * @param {*} d 断言失败消息数据
 * @param {*} e 断言失败消息数据
 * @param {*} f 断言失败消息数据
 */
var invariant = function (condition, format, a, b, c, d, e, f) {
 
    if (condition) {
        return;
    }
 
    if (!format) {
        throw new Error(''
            + 'Minified exception occurred; use the non-minified dev environment '
            + 'for the full error message and additional helpful warnings.'
        );
    }
 
    var args = [a, b, c, d, e, f];
    var argIndex = 0;
 
    var message = ''
        + 'Invariant Violation: '
        + format.replace(/%s/g, function () {
            return args[argIndex++];
        });
 
    throw new Error(message);
 
};
 
/* eslint-enable max-params */
 
module.exports = invariant;