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