react-router
Version:
A complete routing library for React
66 lines (55 loc) • 1.97 kB
JavaScript
import warning from './routerWarning';
export var canUseMembrane = false;
// No-op by default.
var deprecateObjectProperties = function deprecateObjectProperties(object) {
return object;
};
if (process.env.NODE_ENV !== 'production') {
try {
if (Object.defineProperty({}, 'x', {
get: function get() {
return true;
}
}).x) {
canUseMembrane = true;
}
/* eslint-disable no-empty */
} catch (e) {}
/* eslint-enable no-empty */
if (canUseMembrane) {
deprecateObjectProperties = function deprecateObjectProperties(object, message) {
// Wrap the deprecated object in a membrane to warn on property access.
var membrane = {};
var _loop = function _loop(prop) {
if (!Object.prototype.hasOwnProperty.call(object, prop)) {
return 'continue';
}
if (typeof object[prop] === 'function') {
// Can't use fat arrow here because of use of arguments below.
membrane[prop] = function () {
process.env.NODE_ENV !== 'production' ? warning(false, message) : void 0;
return object[prop].apply(object, arguments);
};
return 'continue';
}
// These properties are non-enumerable to prevent React dev tools from
// seeing them and causing spurious warnings when accessing them. In
// principle this could be done with a proxy, but support for the
// ownKeys trap on proxies is not universal, even among browsers that
// otherwise support proxies.
Object.defineProperty(membrane, prop, {
get: function get() {
process.env.NODE_ENV !== 'production' ? warning(false, message) : void 0;
return object[prop];
}
});
};
for (var prop in object) {
var _ret = _loop(prop);
if (_ret === 'continue') continue;
}
return membrane;
};
}
}
export default deprecateObjectProperties;