factoryWithThrowingShims.js 1.6 KB

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