|
5 | 5 | * LICENSE file in the root directory of this source tree. |
6 | 6 | */ |
7 | 7 |
|
| 8 | +import lowPriorityWarningWithoutStack from 'shared/lowPriorityWarningWithoutStack'; |
| 9 | +import ReactSharedInternals from 'shared/ReactSharedInternals'; |
| 10 | + |
8 | 11 | /** |
9 | | - * Forked from fbjs/warning: |
10 | | - * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js |
11 | | - * |
12 | | - * Only change is we use console.warn instead of console.error, |
13 | | - * and do nothing when 'console' is not supported. |
14 | | - * This really simplifies the code. |
15 | | - * --- |
16 | 12 | * Similar to invariant but only logs a warning if the condition is not met. |
17 | 13 | * This can be used to log issues in development environments in critical |
18 | 14 | * paths. Removing the logging code for production environments will keep the |
19 | 15 | * same logic and follow the same code paths. |
20 | 16 | */ |
21 | 17 |
|
22 | | -let lowPriorityWarning = function() {}; |
| 18 | +let lowPriorityWarning = lowPriorityWarningWithoutStack; |
23 | 19 |
|
24 | 20 | if (__DEV__) { |
25 | | - const printWarning = function(format, ...args) { |
26 | | - let argIndex = 0; |
27 | | - const message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]); |
28 | | - if (typeof console !== 'undefined') { |
29 | | - console.warn(message); |
30 | | - } |
31 | | - try { |
32 | | - // --- Welcome to debugging React --- |
33 | | - // This error was thrown as a convenience so that you can use this stack |
34 | | - // to find the callsite that caused this warning to fire. |
35 | | - throw new Error(message); |
36 | | - } catch (x) {} |
37 | | - }; |
38 | | - |
39 | 21 | lowPriorityWarning = function(condition, format, ...args) { |
40 | | - if (format === undefined) { |
41 | | - throw new Error( |
42 | | - '`lowPriorityWarning(condition, format, ...args)` requires a warning ' + |
43 | | - 'message argument', |
44 | | - ); |
45 | | - } |
46 | | - if (!condition) { |
47 | | - printWarning(format, ...args); |
| 22 | + if (condition) { |
| 23 | + return; |
48 | 24 | } |
| 25 | + const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; |
| 26 | + const stack = ReactDebugCurrentFrame.getStackAddendum(); |
| 27 | + // eslint-disable-next-line react-internal/warning-and-invariant-args |
| 28 | + lowPriorityWarningWithoutStack(false, format + '%s', ...args, stack); |
49 | 29 | }; |
50 | 30 | } |
51 | 31 |
|
|
0 commit comments