-
Notifications
You must be signed in to change notification settings - Fork 65
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
1 parent
a6f2918
commit a9ace8d
Showing
8 changed files
with
85 additions
and
105 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
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
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
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
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 |
---|---|---|
@@ -1,54 +1,30 @@ | ||
// Ported version of Facebook's warning module: | ||
// https://github.com/BerkeleyTrue/warning/blob/master/warning.js | ||
// Ported from tiny-warning: | ||
// https://github.com/alexreardon/tiny-warning/blob/master/src/index.js | ||
// -------------------------------------------- | ||
// Since we don't care about whether or not there is a condition passed | ||
// we modified the original to account for that. | ||
|
||
export let warning = (_format: string) => {}; // tslint:disable-line | ||
const isProduction: boolean = process.env.NODE_ENV === 'production'; | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
const printWarning = (format: string, ...args: any[]) => { | ||
// @ts-ignore | ||
const len = arguments.length; | ||
export const warning = (message: string): void => { | ||
// don't do anything in production | ||
// wrapping in production check for better dead code elimination | ||
if (!isProduction) { | ||
// Condition not passed | ||
const text: string = `Warning: ${message}`; | ||
|
||
args = new Array(len > 1 ? len - 1 : 0); | ||
|
||
for (let key = 1; key < len; key++) { | ||
// @ts-ignore | ||
args[key - 1] = arguments[key]; | ||
} | ||
|
||
let argIndex = 0; | ||
|
||
const message = | ||
'Warning: ' + | ||
format.replace(/%s/g, () => { | ||
return args[argIndex++]; | ||
}); | ||
// check console for IE9 support which provides console | ||
// only with open devtools | ||
if (typeof console !== 'undefined') { | ||
console.error(message); // tslint:disable-line | ||
} | ||
try { | ||
throw new Error(message); | ||
} catch (x) {} // tslint:disable-line | ||
}; | ||
|
||
warning = (format: string, ...args: any[]) => { | ||
// @ts-ignore | ||
const len = arguments.length; | ||
|
||
args = new Array(len > 2 ? len - 2 : 0); | ||
|
||
for (let key = 2; key < len; key++) { | ||
// @ts-ignore | ||
args[key - 2] = arguments[key]; | ||
console.warn(text); // tslint:disable-line no-console | ||
} | ||
|
||
if (format === undefined) { | ||
throw new Error('`warning(format, ...args)` requires a warning ' + 'message argument'); | ||
} | ||
|
||
// @ts-ignore | ||
printWarning.apply(null, [format].concat(args)); | ||
}; | ||
} | ||
// Throwing an error and catching it immediately | ||
// to improve debugging | ||
// A consumer can use 'pause on caught exceptions' | ||
// https://github.com/facebook/react/issues/4216 | ||
try { | ||
throw Error(text); | ||
} catch (x) {} // tslint:disable-line no-empty | ||
} | ||
}; |
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
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
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