Skip to content

Commit

Permalink
prep warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
walaura committed Dec 10, 2019
1 parent d901e39 commit b3bb398
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
7 changes: 2 additions & 5 deletions packages/shared/lowPriorityWarning.js
Expand Up @@ -18,13 +18,10 @@ import ReactSharedInternals from 'shared/ReactSharedInternals';
let lowPriorityWarning = lowPriorityWarningWithoutStack;

if (__DEV__) {
lowPriorityWarning = function(condition, format, ...args) {
if (condition) {
return;
}
lowPriorityWarning = function(format, ...args) {
const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
const stack = ReactDebugCurrentFrame.getStackAddendum();
// eslint-disable-next-line react-internal/warning-and-invariant-args
// eslint-disable-next-line react-internal/warning-args
lowPriorityWarningWithoutStack(false, format + '%s', ...args, stack);
};
}
Expand Down
7 changes: 3 additions & 4 deletions packages/shared/lowPriorityWarningWithoutStack.js
Expand Up @@ -36,16 +36,15 @@ if (__DEV__) {
} catch (x) {}
};

lowPriorityWarningWithoutStack = function(condition, format, ...args) {
lowPriorityWarningWithoutStack = function(format, ...args) {
if (format === undefined) {
throw new Error(
'`lowPriorityWarningWithoutStack(condition, format, ...args)` requires a warning ' +
'message argument',
);
}
if (!condition) {
printWarning(format, ...args);
}

printWarning(format, ...args);
};
}

Expand Down
7 changes: 2 additions & 5 deletions packages/shared/warning.js
Expand Up @@ -18,13 +18,10 @@ import ReactSharedInternals from 'shared/ReactSharedInternals';
let warning = warningWithoutStack;

if (__DEV__) {
warning = function(condition, format, ...args) {
if (condition) {
return;
}
warning = function(format, ...args) {
const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
const stack = ReactDebugCurrentFrame.getStackAddendum();
// eslint-disable-next-line react-internal/warning-and-invariant-args
// eslint-disable-next-line react-internal/warning-args
warningWithoutStack(false, format + '%s', ...args, stack);
};
}
Expand Down
6 changes: 1 addition & 5 deletions packages/shared/warningWithoutStack.js
Expand Up @@ -6,7 +6,6 @@
*/

/**
* 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.
Expand All @@ -15,7 +14,7 @@
let warningWithoutStack = () => {};

if (__DEV__) {
warningWithoutStack = function(condition, format, ...args) {
warningWithoutStack = function(format, ...args) {
if (format === undefined) {
throw new Error(
'`warningWithoutStack(condition, format, ...args)` requires a warning ' +
Expand All @@ -28,9 +27,6 @@ if (__DEV__) {
'warningWithoutStack() currently supports at most 8 arguments.',
);
}
if (condition) {
return;
}
if (typeof console !== 'undefined') {
const argsWithFormat = args.map(item => '' + item);
argsWithFormat.unshift('Warning: ' + format);
Expand Down

0 comments on commit b3bb398

Please sign in to comment.