Skip to content

Commit 65291e9

Browse files
committed
Fork warning.js from [email protected]
1 parent bdc8390 commit 65291e9

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

modules/Route.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var assign = require('react/lib/Object.assign');
22
var invariant = require('invariant');
3-
var warning = require('react/lib/warning');
3+
var warning = require('./warning');
44
var PathUtils = require('./PathUtils');
55

66
var _currentRoute;

modules/createRouter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* jshint -W058 */
22
var React = require('react');
3-
var warning = require('react/lib/warning');
3+
var warning = require('./warning');
44
var invariant = require('invariant');
55
var canUseDOM = require('can-use-dom');
66
var LocationActions = require('./actions/LocationActions');

modules/createRoutesFromReactChildren.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* jshint -W084 */
22
var React = require('react');
33
var assign = require('react/lib/Object.assign');
4-
var warning = require('react/lib/warning');
4+
var warning = require('./warning');
55
var DefaultRoute = require('./components/DefaultRoute');
66
var NotFoundRoute = require('./components/NotFoundRoute');
77
var Redirect = require('./components/Redirect');

modules/warning.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright 2014-2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of https://github.com/facebook/react/tree/0.13-stable.
7+
* An additional grant of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @providesModule warning
10+
*/
11+
12+
"use strict";
13+
14+
/**
15+
* Similar to invariant but only logs a warning if the condition is not met.
16+
* This can be used to log issues in development environments in critical
17+
* paths. Removing the logging code for production environments will keep the
18+
* same logic and follow the same code paths.
19+
*/
20+
21+
var __DEV__ = process.env.NODE_ENV !== 'production';
22+
23+
var warning = function () {};
24+
25+
if (__DEV__) {
26+
warning = function(condition, format, ...args) {
27+
if (format === undefined) {
28+
throw new Error(
29+
'`warning(condition, format, ...args)` requires a warning ' +
30+
'message argument'
31+
);
32+
}
33+
34+
if (format.length < 10 || /^[s\W]*$/.test(format)) {
35+
throw new Error(
36+
'The warning format should be able to uniquely identify this ' +
37+
'warning. Please, use a more descriptive format than: ' + format
38+
);
39+
}
40+
41+
if (format.indexOf('Failed Composite propType: ') === 0) {
42+
return; // Ignore CompositeComponent proptype check.
43+
}
44+
45+
if (!condition) {
46+
var argIndex = 0;
47+
var message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]);
48+
console.warn(message);
49+
try {
50+
// --- Welcome to debugging React ---
51+
// This error was thrown as a convenience so that you can use this stack
52+
// to find the callsite that caused this warning to fire.
53+
throw new Error(message);
54+
} catch(x) {}
55+
}
56+
};
57+
}
58+
59+
module.exports = warning;

0 commit comments

Comments
 (0)