Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 51016
1
/**
2
* Copyright (c) 2014-2015, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule invariant
10
*/
11
12
"use strict";
13
14
/**
15
* Use invariant() to assert state which your program assumes to be true.
16
*
17
* Provide sprintf-style format (only %s is supported) and arguments
18
* to provide information about what broke and what you were
19
* expecting.
20
*
21
* The invariant message will be stripped in production, but the invariant
22
* will remain to ensure logic does not differ in production.
23
*/
24
25
var invariant = function(condition, format, a, b, c, d, e, f) {
26
if (__DEV__) {
27
if (format === undefined) {
28
throw new Error('invariant requires an error message argument');
29
}
30
}
31
32
if (!condition) {
33
var error;
34
if (format === undefined) {
35
error = new Error(
36
'Minified exception occurred; use the non-minified dev environment ' +
37
'for the full error message and additional helpful warnings.'
38
);
39
} else {
40
var args = [a, b, c, d, e, f];
41
var argIndex = 0;
42
error = new Error(
43
'Invariant Violation: ' +
44
format.replace(/%s/g, function() { return args[argIndex++]; })
45
);
46
}
47
48
error.framesToPop = 1; // we don't care about invariant's own frame
49
throw error;
50
}
51
};
52
53
module.exports = invariant;
54
55