main
js 34 lines 1.09 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10 let hasConfirmedEval = false;
11 export function checkEvalAvailabilityOnceDev(): void {
12 if (__DEV__) {
13 if (!hasConfirmedEval) {
14 hasConfirmedEval = true;
15 try {
16 // eslint-disable-next-line no-eval
17 (0, eval)('null');
18 } catch {
19 console.error(
20 'eval() is not supported in this environment. ' +
21 'React requires eval() in development mode for various debugging features ' +
22 'like reconstructing callstacks from a different environment.\n' +
23 'React will never use eval() in production mode',
24 );
25 }
26 }
27 } else {
28 // These errors should never make it into a build so we don't need to encode them in codes.json
29 // eslint-disable-next-line react-internal/prod-error-codes
30 throw new Error(
31 'checkEvalAvailabilityOnceDev should never be called in production mode. This is a bug in React.',
32 );
33 }
34 }