MessagesForMacintosh/JS/node_modules/apollo-utilities/lib/util/maybeDeepFreeze.js

25 lines
835 B
JavaScript
Raw Normal View History

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var environment_1 = require("./environment");
function deepFreeze(o) {
Object.freeze(o);
Object.getOwnPropertyNames(o).forEach(function (prop) {
if (o[prop] !== null &&
(typeof o[prop] === 'object' || typeof o[prop] === 'function') &&
!Object.isFrozen(o[prop])) {
deepFreeze(o[prop]);
}
});
return o;
}
function maybeDeepFreeze(obj) {
if (environment_1.isDevelopment() || environment_1.isTest()) {
var symbolIsPolyfilled = typeof Symbol === 'function' && typeof Symbol('') === 'string';
if (!symbolIsPolyfilled) {
return deepFreeze(obj);
}
}
return obj;
}
exports.maybeDeepFreeze = maybeDeepFreeze;
//# sourceMappingURL=maybeDeepFreeze.js.map