-
Notifications
You must be signed in to change notification settings - Fork 47.5k
/
Copy pathwarningWithoutStack.js
44 lines (40 loc) · 1.35 KB
/
warningWithoutStack.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* 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.
*/
/**
* Similar to invariant but only logs a warning if the condition is not met.
* This can be used to log issues in development environments in critical
* paths. Removing the logging code for production environments will keep the
* same logic and follow the same code paths.
*/
let warningWithoutStack = () => {};
if (__DEV__) {
warningWithoutStack = function(condition, format, ...args) {
if (format === undefined) {
throw new Error(
'`warningWithoutStack(condition, format, ...args)` requires a warning ' +
'message argument',
);
}
if (condition) {
return;
}
if (typeof console !== 'undefined') {
const stringArgs = args.map(item => '' + item);
console.error('Warning: ' + format, ...stringArgs);
}
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
let argIndex = 0;
const message =
'Warning: ' + format.replace(/%s/g, () => args[argIndex++]);
throw new Error(message);
} catch (x) {}
};
}
export default warningWithoutStack;