-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: andycall <dongtiangche@outlook.com>
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
let warning = () => {}; | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
warning = (condition, format, ...args) => { | ||
if (format === undefined) { | ||
throw new Error( | ||
'`warningWithoutStack(condition, format, ...args)` requires a warning ' + | ||
'message argument', | ||
); | ||
} | ||
if (args.length > 8) { | ||
// Check before the condition to catch violations early. | ||
throw new Error( | ||
'warningWithoutStack() currently supports at most 8 arguments.', | ||
); | ||
} | ||
if (condition) { | ||
return; | ||
} | ||
if (typeof console !== 'undefined') { | ||
const argsWithFormat = args.map(item => '' + item); | ||
argsWithFormat.unshift('Warning: ' + format); | ||
|
||
Function.prototype.apply.call(console.error, console, argsWithFormat); | ||
} | ||
try { | ||
// 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 warning; |