Skip to content

Commit 0572ddd

Browse files
EmeegeemeeBerkeleyTrue
authored andcommitted
fix: Update warning to use the latest version from facebook/fbjs
BREAKING CHANGE: This changes the internal workings. A major release is made to ensure minimal effect on downstream users.
1 parent 3dad9ee commit 0572ddd

File tree

4 files changed

+62
-66
lines changed

4 files changed

+62
-66
lines changed

browser.js

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
2-
* Copyright 2014-2015, Facebook, Inc.
3-
* All rights reserved.
2+
* Copyright (c) 2014-present, Facebook, Inc.
43
*
5-
* This source code is licensed under the BSD-style license found in the
6-
* LICENSE file in the root directory of this source tree. An additional grant
7-
* of patent rights can be found in the PATENTS file in the same directory.
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @providesModule warning
88
*/
99

1010
'use strict';
@@ -19,40 +19,42 @@
1919
var warning = function() {};
2020

2121
if (process.env.NODE_ENV !== 'production') {
22-
warning = function(condition, format, args) {
22+
function printWarning(format, args) {
2323
var len = arguments.length;
2424
args = new Array(len > 2 ? len - 2 : 0);
2525
for (var key = 2; key < len; key++) {
2626
args[key - 2] = arguments[key];
2727
}
28-
if (format === undefined) {
29-
throw new Error(
30-
'`warning(condition, format, ...args)` requires a warning ' +
31-
'message argument'
32-
);
28+
var argIndex = 0;
29+
var message = 'Warning: ' +
30+
format.replace(/%s/g, function() {
31+
return args[argIndex++];
32+
});
33+
if (typeof console !== 'undefined') {
34+
console.error(message);
3335
}
36+
try {
37+
// --- Welcome to debugging React ---
38+
// This error was thrown as a convenience so that you can use this stack
39+
// to find the callsite that caused this warning to fire.
40+
throw new Error(message);
41+
} catch (x) {}
42+
}
3443

35-
if (format.length < 10 || (/^[s\W]*$/).test(format)) {
44+
warning = function(condition, format, args) {
45+
var len = arguments.length;
46+
args = new Array(len > 2 ? len - 2 : 0);
47+
for (var key = 2; key < len; key++) {
48+
args[key - 2] = arguments[key];
49+
}
50+
if (format === undefined) {
3651
throw new Error(
37-
'The warning format should be able to uniquely identify this ' +
38-
'warning. Please, use a more descriptive format than: ' + format
52+
'`warning(condition, format, ...args)` requires a warning ' +
53+
'message argument'
3954
);
4055
}
41-
4256
if (!condition) {
43-
var argIndex = 0;
44-
var message = 'Warning: ' +
45-
format.replace(/%s/g, function() {
46-
return args[argIndex++];
47-
});
48-
if (typeof console !== 'undefined') {
49-
console.error(message);
50-
}
51-
try {
52-
// This error was thrown as a convenience so that you can use this stack
53-
// to find the callsite that caused this warning to fire.
54-
throw new Error(message);
55-
} catch(x) {}
57+
printWarning.apply(null, [format].concat(args));
5658
}
5759
};
5860
}

test/package/development.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ module.exports = function(t) {
99
warning(false);
1010
}, /requires a warning/i);
1111

12-
t.throws(function() {
13-
warning(true, 'short');
14-
}, /use a more descriptive format/i);
15-
16-
t.throws(function() {
17-
warning(false, 'short');
18-
}, /use a more descriptive format/i);
19-
2012
var error = console.error;
2113

2214
console.error = function(msg) {

test/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ var vm = require('vm');
77
var file = __dirname + '/package/' + process.env.NODE_ENV + '.js';
88

99
test('node', function(t) {
10-
t.plan(5);
10+
t.plan(3);
1111
require(file)(t);
1212
});
1313

1414
test('browserify', function(t) {
15-
t.plan(8);
15+
t.plan(6);
1616
var b = browserify({
1717
entries: file,
1818
standalone: 'package'

warning.js

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
2-
* Copyright 2014-2015, Facebook, Inc.
3-
* All rights reserved.
2+
* Copyright (c) 2014-present, Facebook, Inc.
43
*
5-
* This source code is licensed under the BSD-style license found in the
6-
* LICENSE file in the root directory of this source tree. An additional grant
7-
* of patent rights can be found in the PATENTS file in the same directory.
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @providesModule warning
88
*/
99

1010
'use strict';
@@ -21,40 +21,42 @@ var __DEV__ = process.env.NODE_ENV !== 'production';
2121
var warning = function() {};
2222

2323
if (__DEV__) {
24-
warning = function(condition, format, args) {
24+
function printWarning(format, args) {
2525
var len = arguments.length;
2626
args = new Array(len > 2 ? len - 2 : 0);
2727
for (var key = 2; key < len; key++) {
2828
args[key - 2] = arguments[key];
2929
}
30-
if (format === undefined) {
31-
throw new Error(
32-
'`warning(condition, format, ...args)` requires a warning ' +
33-
'message argument'
34-
);
30+
var argIndex = 0;
31+
var message = 'Warning: ' +
32+
format.replace(/%s/g, function() {
33+
return args[argIndex++];
34+
});
35+
if (typeof console !== 'undefined') {
36+
console.error(message);
3537
}
38+
try {
39+
// --- Welcome to debugging React ---
40+
// This error was thrown as a convenience so that you can use this stack
41+
// to find the callsite that caused this warning to fire.
42+
throw new Error(message);
43+
} catch (x) {}
44+
}
3645

37-
if (format.length < 10 || (/^[s\W]*$/).test(format)) {
46+
warning = function(condition, format, args) {
47+
var len = arguments.length;
48+
args = new Array(len > 2 ? len - 2 : 0);
49+
for (var key = 2; key < len; key++) {
50+
args[key - 2] = arguments[key];
51+
}
52+
if (format === undefined) {
3853
throw new Error(
39-
'The warning format should be able to uniquely identify this ' +
40-
'warning. Please, use a more descriptive format than: ' + format
54+
'`warning(condition, format, ...args)` requires a warning ' +
55+
'message argument'
4156
);
4257
}
43-
4458
if (!condition) {
45-
var argIndex = 0;
46-
var message = 'Warning: ' +
47-
format.replace(/%s/g, function() {
48-
return args[argIndex++];
49-
});
50-
if (typeof console !== 'undefined') {
51-
console.error(message);
52-
}
53-
try {
54-
// This error was thrown as a convenience so that you can use this stack
55-
// to find the callsite that caused this warning to fire.
56-
throw new Error(message);
57-
} catch(x) {}
59+
printWarning.apply(null, [format].concat(args));
5860
}
5961
};
6062
}

0 commit comments

Comments
 (0)