Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit 07d1b47

Browse files
committed
Remove fbjs dependency
1 parent 7cc8c81 commit 07d1b47

File tree

5 files changed

+71
-44
lines changed

5 files changed

+71
-44
lines changed

checkPropTypes.js

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,24 @@
77

88
'use strict';
99

10+
var printWarning = function() {};
11+
1012
if (process.env.NODE_ENV !== 'production') {
11-
var invariant = require('fbjs/lib/invariant');
12-
var warning = require('fbjs/lib/warning');
1313
var ReactPropTypesSecret = require('./lib/ReactPropTypesSecret');
1414
var loggedTypeFailures = {};
15+
16+
printWarning = function(text) {
17+
var message = 'Warning: ' + text;
18+
if (typeof console !== 'undefined') {
19+
console.error(message);
20+
}
21+
try {
22+
// --- Welcome to debugging React ---
23+
// This error was thrown as a convenience so that you can use this stack
24+
// to find the callsite that caused this warning to fire.
25+
throw new Error(message);
26+
} catch (x) {}
27+
};
1528
}
1629

1730
/**
@@ -36,20 +49,37 @@ function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
3649
try {
3750
// This is intentionally an invariant that gets caught. It's the same
3851
// behavior as without this statement except with a better message.
39-
invariant(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'the `prop-types` package, but received `%s`.', componentName || 'React class', location, typeSpecName, typeof typeSpecs[typeSpecName]);
52+
if (typeof typeSpecs[typeSpecName] !== 'function') {
53+
throw new Error(
54+
(componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
55+
'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
56+
);
57+
}
4058
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
4159
} catch (ex) {
4260
error = ex;
4361
}
44-
warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error);
62+
if (error && !(error instanceof Error)) {
63+
printWarning(
64+
(componentName || 'React class') + ': type specification of ' +
65+
location + ' `' + typeSpecName + '` is invalid; the type checker ' +
66+
'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
67+
'You may have forgotten to pass an argument to the type checker ' +
68+
'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
69+
'shape all require an argument).'
70+
)
71+
72+
}
4573
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
4674
// Only monitor this failure once because there tends to be a lot of the
4775
// same error.
4876
loggedTypeFailures[error.message] = true;
4977

5078
var stack = getStack ? getStack() : '';
5179

52-
warning(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : '');
80+
printWarning(
81+
'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
82+
);
5383
}
5484
}
5585
}

factoryWithThrowingShims.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77

88
'use strict';
99

10-
var emptyFunction = require('fbjs/lib/emptyFunction');
11-
var invariant = require('fbjs/lib/invariant');
1210
var ReactPropTypesSecret = require('./lib/ReactPropTypesSecret');
1311

12+
function emptyFunction() {}
13+
1414
module.exports = function() {
1515
function shim(props, propName, componentName, location, propFullName, secret) {
1616
if (secret === ReactPropTypesSecret) {
1717
// It is still safe when called from React.
1818
return;
1919
}
20-
invariant(
21-
false,
20+
throw new Error(
2221
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
2322
'Use PropTypes.checkPropTypes() to call them. ' +
2423
'Read more at http://fb.me/use-check-prop-types'

factoryWithTypeCheckers.js

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,32 @@
77

88
'use strict';
99

10-
var emptyFunction = require('fbjs/lib/emptyFunction');
11-
var invariant = require('fbjs/lib/invariant');
12-
var warning = require('fbjs/lib/warning');
1310
var assign = require('object-assign');
1411

1512
var ReactPropTypesSecret = require('./lib/ReactPropTypesSecret');
1613
var checkPropTypes = require('./checkPropTypes');
1714

15+
var printWarning = function() {};
16+
17+
if (process.env.NODE_ENV !== 'production') {
18+
printWarning = function(text) {
19+
var message = 'Warning: ' + text;
20+
if (typeof console !== 'undefined') {
21+
console.error(message);
22+
}
23+
try {
24+
// --- Welcome to debugging React ---
25+
// This error was thrown as a convenience so that you can use this stack
26+
// to find the callsite that caused this warning to fire.
27+
throw new Error(message);
28+
} catch (x) {}
29+
};
30+
}
31+
32+
function emptyFunctionThatReturnsNull() {
33+
return null;
34+
}
35+
1836
module.exports = function(isValidElement, throwOnDirectAccess) {
1937
/* global Symbol */
2038
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
@@ -157,8 +175,7 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
157175
if (secret !== ReactPropTypesSecret) {
158176
if (throwOnDirectAccess) {
159177
// New behavior only for users of `prop-types` package
160-
invariant(
161-
false,
178+
throw new Error(
162179
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
163180
'Use `PropTypes.checkPropTypes()` to call them. ' +
164181
'Read more at http://fb.me/use-check-prop-types'
@@ -171,15 +188,12 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
171188
// Avoid spamming the console because they are often not actionable except for lib authors
172189
manualPropTypeWarningCount < 3
173190
) {
174-
warning(
175-
false,
191+
printWarning(
176192
'You are manually calling a React.PropTypes validation ' +
177-
'function for the `%s` prop on `%s`. This is deprecated ' +
193+
'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +
178194
'and will throw in the standalone `prop-types` package. ' +
179195
'You may be seeing this warning due to a third-party PropTypes ' +
180-
'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.',
181-
propFullName,
182-
componentName
196+
'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'
183197
);
184198
manualPropTypeCallCache[cacheKey] = true;
185199
manualPropTypeWarningCount++;
@@ -223,7 +237,7 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
223237
}
224238

225239
function createAnyTypeChecker() {
226-
return createChainableTypeChecker(emptyFunction.thatReturnsNull);
240+
return createChainableTypeChecker(emptyFunctionThatReturnsNull);
227241
}
228242

229243
function createArrayOfTypeChecker(typeChecker) {
@@ -273,8 +287,8 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
273287

274288
function createEnumTypeChecker(expectedValues) {
275289
if (!Array.isArray(expectedValues)) {
276-
process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0;
277-
return emptyFunction.thatReturnsNull;
290+
process.env.NODE_ENV !== 'production' ? printWarning('Invalid argument supplied to oneOf, expected an instance of array.') : void 0;
291+
return emptyFunctionThatReturnsNull;
278292
}
279293

280294
function validate(props, propName, componentName, location, propFullName) {
@@ -316,21 +330,18 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
316330

317331
function createUnionTypeChecker(arrayOfTypeCheckers) {
318332
if (!Array.isArray(arrayOfTypeCheckers)) {
319-
process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
320-
return emptyFunction.thatReturnsNull;
333+
process.env.NODE_ENV !== 'production' ? printWarning('Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
334+
return emptyFunctionThatReturnsNull;
321335
}
322336

323337
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
324338
var checker = arrayOfTypeCheckers[i];
325339
if (typeof checker !== 'function') {
326-
warning(
327-
false,
340+
printWarning(
328341
'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' +
329-
'received %s at index %s.',
330-
getPostfixForTypeWarning(checker),
331-
i
342+
'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.'
332343
);
333-
return emptyFunction.thatReturnsNull;
344+
return emptyFunctionThatReturnsNull;
334345
}
335346
}
336347

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
},
2626
"homepage": "https://facebook.github.io/react/",
2727
"dependencies": {
28-
"fbjs": "^0.8.16",
2928
"loose-envify": "^1.3.1",
3029
"object-assign": "^4.1.1"
3130
},

yarn.lock

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,18 +1049,6 @@ fb-watchman@^2.0.0:
10491049
dependencies:
10501050
bser "^2.0.0"
10511051

1052-
fbjs@^0.8.16:
1053-
version "0.8.16"
1054-
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.16.tgz#5e67432f550dc41b572bf55847b8aca64e5337db"
1055-
dependencies:
1056-
core-js "^1.0.0"
1057-
isomorphic-fetch "^2.1.1"
1058-
loose-envify "^1.0.0"
1059-
object-assign "^4.1.0"
1060-
promise "^7.1.1"
1061-
setimmediate "^1.0.5"
1062-
ua-parser-js "^0.7.9"
1063-
10641052
fbjs@^0.8.9:
10651053
version "0.8.12"
10661054
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.12.tgz#10b5d92f76d45575fd63a217d4ea02bea2f8ed04"

0 commit comments

Comments
 (0)