browser.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * Copyright 2013-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. 'use strict';
  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. var invariant = function(condition, format, a, b, c, d, e, f) {
  21. if (process.env.NODE_ENV !== 'production') {
  22. if (format === undefined) {
  23. throw new Error('invariant requires an error message argument');
  24. }
  25. }
  26. if (!condition) {
  27. var error;
  28. if (format === undefined) {
  29. error = new Error(
  30. 'Minified exception occurred; use the non-minified dev environment ' +
  31. 'for the full error message and additional helpful warnings.'
  32. );
  33. } else {
  34. var args = [a, b, c, d, e, f];
  35. var argIndex = 0;
  36. error = new Error(
  37. format.replace(/%s/g, function() { return args[argIndex++]; })
  38. );
  39. error.name = 'Invariant Violation';
  40. }
  41. error.framesToPop = 1; // we don't care about invariant's own frame
  42. throw error;
  43. }
  44. };
  45. module.exports = invariant;