跳到主要内容

作用

仅在开发时检查评估可用性

export function checkEvalAvailabilityOnceDev(): void {
if (__DEV__) {
if (!hasConfirmedEval) {
hasConfirmedEval = true;
try {
(0, eval)('null');
} catch {
console.error(
'eval() is not supported in this environment. ' +
'This can happen if you started the Node.js process with --disallow-code-generation-from-strings, ' +
'or if `eval` was patched by other means. ' +
'React requires eval() in development mode for various debugging features ' +
'like reconstructing callstacks from a different environment.\n' +
'React will never use eval() in production mode',
);
}
}
} else {
// These errors should never make it into a build so we don't need to encode them in codes.json
// 这些错误绝不应该出现在构建中,所以我们不需要在 codes.json 中对它们进行编码
throw new Error(
'checkEvalAvailabilityOnceDev should never be called in production mode. This is a bug in React.',
);
}
}

变量

已确认评估

备注

源码中 10 行

let hasConfirmedEval = false;