2019-12-15 02:09:25 +08:00
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import ReactSharedInternals from 'shared/ReactSharedInternals';
|
|
|
|
|
|
2021-08-26 06:35:38 +08:00
|
|
|
let suppressWarning = false;
|
|
|
|
|
export function setSuppressWarning(newSuppressWarning) {
|
|
|
|
|
if (__DEV__) {
|
|
|
|
|
suppressWarning = newSuppressWarning;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-15 02:09:25 +08:00
|
|
|
// In DEV, calls to console.warn and console.error get replaced
|
|
|
|
|
// by calls to these methods by a Babel plugin.
|
|
|
|
|
//
|
|
|
|
|
// In PROD (or in packages without access to React internals),
|
|
|
|
|
// they are left as they are instead.
|
|
|
|
|
|
|
|
|
|
export function warn(format, ...args) {
|
|
|
|
|
if (__DEV__) {
|
2021-08-26 06:35:38 +08:00
|
|
|
if (!suppressWarning) {
|
|
|
|
|
printWarning('warn', format, args);
|
|
|
|
|
}
|
2019-12-15 02:09:25 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function error(format, ...args) {
|
|
|
|
|
if (__DEV__) {
|
2021-08-26 06:35:38 +08:00
|
|
|
if (!suppressWarning) {
|
|
|
|
|
printWarning('error', format, args);
|
|
|
|
|
}
|
2019-12-15 02:09:25 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function printWarning(level, format, args) {
|
2019-12-17 23:21:18 +08:00
|
|
|
// When changing this logic, you might want to also
|
|
|
|
|
// update consoleWithStackDev.www.js as well.
|
2019-12-15 02:09:25 +08:00
|
|
|
if (__DEV__) {
|
2020-04-22 00:22:46 +08:00
|
|
|
const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
|
|
|
|
const stack = ReactDebugCurrentFrame.getStackAddendum();
|
|
|
|
|
if (stack !== '') {
|
|
|
|
|
format += '%s';
|
|
|
|
|
args = args.concat([stack]);
|
2019-12-15 02:09:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const argsWithFormat = args.map(item => '' + item);
|
|
|
|
|
// Careful: RN currently depends on this prefix
|
|
|
|
|
argsWithFormat.unshift('Warning: ' + format);
|
|
|
|
|
// We intentionally don't use spread (or .apply) directly because it
|
|
|
|
|
// breaks IE9: https://github.com/facebook/react/issues/13610
|
|
|
|
|
// eslint-disable-next-line react-internal/no-production-logging
|
|
|
|
|
Function.prototype.apply.call(console[level], console, argsWithFormat);
|
|
|
|
|
}
|
|
|
|
|
}
|