react/packages/shared/hasBadMapPolyfill.js
2019-07-19 22:20:28 +01:00

27 lines
745 B
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @flow
*/
export let hasBadMapPolyfill;
if (__DEV__) {
hasBadMapPolyfill = false;
try {
const frozenObject = Object.freeze({});
const testMap = new Map([[frozenObject, null]]);
const testSet = new Set([frozenObject]);
// This is necessary for Rollup to not consider these unused.
// https://github.com/rollup/rollup/issues/1771
// TODO: we can remove these if Rollup fixes the bug.
testMap.set(0, 0);
testSet.add(0);
} catch (e) {
// TODO: Consider warning about bad polyfills
hasBadMapPolyfill = true;
}
}