maybeDeepFreeze.js 835 B

12345678910111213141516171819202122232425
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var environment_1 = require("./environment");
  4. function deepFreeze(o) {
  5. Object.freeze(o);
  6. Object.getOwnPropertyNames(o).forEach(function (prop) {
  7. if (o[prop] !== null &&
  8. (typeof o[prop] === 'object' || typeof o[prop] === 'function') &&
  9. !Object.isFrozen(o[prop])) {
  10. deepFreeze(o[prop]);
  11. }
  12. });
  13. return o;
  14. }
  15. function maybeDeepFreeze(obj) {
  16. if (environment_1.isDevelopment() || environment_1.isTest()) {
  17. var symbolIsPolyfilled = typeof Symbol === 'function' && typeof Symbol('') === 'string';
  18. if (!symbolIsPolyfilled) {
  19. return deepFreeze(obj);
  20. }
  21. }
  22. return obj;
  23. }
  24. exports.maybeDeepFreeze = maybeDeepFreeze;
  25. //# sourceMappingURL=maybeDeepFreeze.js.map