browser.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. /**
  9. * Use invariant() to assert state which your program assumes to be true.
  10. *
  11. * Provide sprintf-style format (only %s is supported) and arguments
  12. * to provide information about what broke and what you were
  13. * expecting.
  14. *
  15. * The invariant message will be stripped in production, but the invariant
  16. * will remain to ensure logic does not differ in production.
  17. */
  18. var invariant = function(condition, format, a, b, c, d, e, f) {
  19. if (process.env.NODE_ENV !== 'production') {
  20. if (format === undefined) {
  21. throw new Error('invariant requires an error message argument');
  22. }
  23. }
  24. if (!condition) {
  25. var error;
  26. if (format === undefined) {
  27. error = new Error(
  28. 'Minified exception occurred; use the non-minified dev environment ' +
  29. 'for the full error message and additional helpful warnings.'
  30. );
  31. } else {
  32. var args = [a, b, c, d, e, f];
  33. var argIndex = 0;
  34. error = new Error(
  35. format.replace(/%s/g, function() { return args[argIndex++]; })
  36. );
  37. error.name = 'Invariant Violation';
  38. }
  39. error.framesToPop = 1; // we don't care about invariant's own frame
  40. throw error;
  41. }
  42. };
  43. module.exports = invariant;