Debian Codegraph @

node/prop-types/factoryWithThrowingShims.js

raw
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 var ReactPropTypesSecret = require('./lib/ReactPropTypesSecret');
11
12 function emptyFunction() {}
13 function emptyFunctionWithReset() {}
14 emptyFunctionWithReset.resetWarningCache = emptyFunction;
15
16 module.exports = function() {
17 function shim(props, propName, componentName, location, propFullName, secret) {
18 if (secret === ReactPropTypesSecret) {
19 // It is still safe when called from React.
20 return;
21 }
22 var err = new Error(
23 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
24 'Use PropTypes.checkPropTypes() to call them. ' +
25 'Read more at http://fb.me/use-check-prop-types'
26 );
27 err.name = 'Invariant Violation';
28 throw err;
29 };
30 shim.isRequired = shim;
31 function getShim() {
32 return shim;
33 };
34 // Important!
35 // Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
36 var ReactPropTypes = {
37 array: shim,
38 bigint: shim,
39 bool: shim,
40 func: shim,
41 number: shim,
42 object: shim,
43 string: shim,
44 symbol: shim,
45
46 any: shim,
47 arrayOf: getShim,
48 element: shim,
49 elementType: shim,
50 instanceOf: getShim,
51 node: shim,
52 objectOf: getShim,
53 oneOf: getShim,
54 oneOfType: getShim,
55 shape: getShim,
56 exact: getShim,
57
58 checkPropTypes: emptyFunctionWithReset,
59 resetWarningCache: emptyFunction
60 };
61
62 ReactPropTypes.PropTypes = ReactPropTypes;
63
64 return ReactPropTypes;
65 };