-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
69 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,60 @@ | ||
/** | ||
* Copyright 2014-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* 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. | ||
*/ | ||
|
||
var warning = function() {}; | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
warning = function(condition, format, args) { | ||
var len = arguments.length; | ||
args = new Array(len > 2 ? len - 2 : 0); | ||
for (var key = 2; key < len; key++) { | ||
args[key - 2] = arguments[key]; | ||
} | ||
if (format === undefined) { | ||
throw new Error( | ||
'`warning(condition, format, ...args)` requires a warning ' + | ||
'message argument' | ||
); | ||
} | ||
|
||
if (format.length < 10 || (/^[s\W]*$/).test(format)) { | ||
throw new Error( | ||
'The warning format should be able to uniquely identify this ' + | ||
'warning. Please, use a more descriptive format than: ' + format | ||
); | ||
} | ||
|
||
if (!condition) { | ||
var argIndex = 0; | ||
var message = 'Warning: ' + | ||
format.replace(/%s/g, function() { | ||
return args[argIndex++]; | ||
}); | ||
if (typeof console !== 'undefined') { | ||
console.error(message); | ||
} | ||
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. | ||
throw new Error(message); | ||
} catch(x) {} | ||
} | ||
}; | ||
} | ||
|
||
module.exports = warning; |
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