Use prop-types instead of prop-types factory (#9526)
Latest versions of prop-types don't depend on React, so the factory is not necessary, and in fact bloats the build because it is intended for 15.5 and so doesn't strip out the checkers in prod.
Andrew Clark committed
Apr 25, 2017 at 14:32 UTC
8ba820a699ed337cf4f42a5743313cb925b6f97b
5 files changed
+110
-117
scripts/fiber/tests-passing.txt
+10
-10
@@ -212,11 +212,11 @@ src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
212
* should not warn for valid values
213
* should be implicitly optional and not warn without values
214
* should warn for missing required values
215
-* should warn if called manually in development
215
+* should throw if called manually in development
216
* should should accept any value
217
* should be implicitly optional and not warn without values
218
* should warn for missing required values
219
-* should warn if called manually in development
219
+* should throw if called manually in development
220
* should fail for invalid argument
221
* should support the arrayOf propTypes
222
* should support arrayOf with complex types
@@ -226,19 +226,19 @@ src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
226
* should not warn when passing an empty array
227
* should be implicitly optional and not warn without values
228
* should warn for missing required values
229
-* should warn if called manually in development
229
+* should throw if called manually in development
230
* should support components
231
* should not support multiple components or scalar values
232
* should be able to define a single child as label
233
* should warn when passing no label and isRequired is set
234
* should be implicitly optional and not warn without values
235
* should warn for missing required values
236
-* should warn if called manually in development
236
+* should throw if called manually in development
237
* should warn for invalid instances
238
* should not warn for valid values
239
* should be implicitly optional and not warn without values
240
* should warn for missing required values
241
-* should warn if called manually in development
241
+* should throw if called manually in development
242
* should warn for invalid values
243
* should not warn for valid values
244
* should not warn for iterables
@@ -246,7 +246,7 @@ src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
246
* should not warn for null/undefined if not required
247
* should warn for missing required values
248
* should accept empty array for required props
249
-* should warn if called manually in development
249
+* should throw if called manually in development
250
* should fail for invalid argument
251
* should support the objectOf propTypes
252
* should support objectOf with complex types
@@ -256,19 +256,19 @@ src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
256
* should not warn when passing an empty object
257
* should be implicitly optional and not warn without values
258
* should warn for missing required values
259
-* should warn if called manually in development
259
+* should throw if called manually in development
260
* should warn but not error for invalid argument
261
* should warn for invalid values
262
* should not warn for valid values
263
* should be implicitly optional and not warn without values
264
* should warn for missing required values
265
-* should warn if called manually in development
265
+* should throw if called manually in development
266
* should warn but not error for invalid argument
267
* should warn if none of the types are valid
268
* should not warn if one of the types are valid
269
* should be implicitly optional and not warn without values
270
* should warn for missing required values
271
-* should warn if called manually in development
271
+* should throw if called manually in development
272
* should warn for non objects
273
* should not warn for empty values
274
* should not warn for an empty object
@@ -279,7 +279,7 @@ src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
279
* should warn for invalid key types
280
* should be implicitly optional and not warn without values
281
* should warn for missing required values
282
-* should warn if called manually in development
282
+* should throw if called manually in development
283
* should warn for non-symbol
284
* should not warn for a polyfilled Symbol
285
* should have been called with the right params
scripts/rollup/bundles.js
-1
@@ -49,7 +49,6 @@ const bundles = [
49
'create-react-class/factory',
50
'prop-types',
51
'prop-types/checkPropTypes',
52
- 'prop-types/factory',
52
],
53
fbEntry: 'src/fb/ReactFBEntry.js',
54
hasteName: 'React',
scripts/rollup/modules.js
-1
@@ -57,7 +57,6 @@ const legacyModules = [
57
'create-react-class/factory',
58
'prop-types',
59
'prop-types/checkPropTypes',
60
- 'prop-types/factory',
60
];
61
62
// this function builds up a very niave Haste-like moduleMap
src/isomorphic/classic/types/ReactPropTypes.js
+1
-4
@@ -11,7 +11,4 @@
11
12
'use strict';
13
14
-var {isValidElement} = require('ReactElement');
15
-var factory = require('prop-types/factory');
16
-
17
-module.exports = factory(isValidElement);
14
+module.exports = require('prop-types');
src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
+99
-101
@@ -96,17 +96,18 @@ function typeCheckPass(declaration, value) {
96
expect(message).toBe(null);
97
}
98
99
-function expectWarningInDevelopment(declaration, value) {
99
+function expectThrowInDevelopment(declaration, value) {
100
var props = {testProp: value};
101
var propName = 'testProp' + Math.random().toString();
102
var componentName = 'testComponent' + Math.random().toString();
103
- resetWarningCache();
104
- for (var i = 0; i < 3; i++) {
103
+ var message;
104
+ try {
105
declaration(props, propName, componentName, 'prop');
106
+ } catch (e) {
107
+ message = e.message;
108
}
107
- expect(console.error.calls.count()).toBe(1);
108
- expect(console.error.calls.argsFor(0)[0]).toContain(
109
- 'You are manually calling a React.PropTypes validation ',
109
+ expect(message).toContain(
110
+ 'Calling PropTypes validators directly is not supported',
111
);
112
console.error.calls.reset();
113
}
@@ -228,50 +229,50 @@ describe('ReactPropTypes', () => {
229
typeCheckFailRequiredValues(PropTypes.string.isRequired);
230
});
231
231
- it('should warn if called manually in development', () => {
232
+ it('should throw if called manually in development', () => {
233
spyOn(console, 'error');
233
- expectWarningInDevelopment(PropTypes.array, /please/);
234
- expectWarningInDevelopment(PropTypes.array, []);
235
- expectWarningInDevelopment(PropTypes.array.isRequired, /please/);
236
- expectWarningInDevelopment(PropTypes.array.isRequired, []);
237
- expectWarningInDevelopment(PropTypes.array.isRequired, null);
238
- expectWarningInDevelopment(PropTypes.array.isRequired, undefined);
239
- expectWarningInDevelopment(PropTypes.bool, []);
240
- expectWarningInDevelopment(PropTypes.bool, true);
241
- expectWarningInDevelopment(PropTypes.bool.isRequired, []);
242
- expectWarningInDevelopment(PropTypes.bool.isRequired, true);
243
- expectWarningInDevelopment(PropTypes.bool.isRequired, null);
244
- expectWarningInDevelopment(PropTypes.bool.isRequired, undefined);
245
- expectWarningInDevelopment(PropTypes.func, false);
246
- expectWarningInDevelopment(PropTypes.func, function() {});
247
- expectWarningInDevelopment(PropTypes.func.isRequired, false);
248
- expectWarningInDevelopment(PropTypes.func.isRequired, function() {});
249
- expectWarningInDevelopment(PropTypes.func.isRequired, null);
250
- expectWarningInDevelopment(PropTypes.func.isRequired, undefined);
251
- expectWarningInDevelopment(PropTypes.number, function() {});
252
- expectWarningInDevelopment(PropTypes.number, 42);
253
- expectWarningInDevelopment(PropTypes.number.isRequired, function() {});
254
- expectWarningInDevelopment(PropTypes.number.isRequired, 42);
255
- expectWarningInDevelopment(PropTypes.number.isRequired, null);
256
- expectWarningInDevelopment(PropTypes.number.isRequired, undefined);
257
- expectWarningInDevelopment(PropTypes.string, 0);
258
- expectWarningInDevelopment(PropTypes.string, 'foo');
259
- expectWarningInDevelopment(PropTypes.string.isRequired, 0);
260
- expectWarningInDevelopment(PropTypes.string.isRequired, 'foo');
261
- expectWarningInDevelopment(PropTypes.string.isRequired, null);
262
- expectWarningInDevelopment(PropTypes.string.isRequired, undefined);
263
- expectWarningInDevelopment(PropTypes.symbol, 0);
264
- expectWarningInDevelopment(PropTypes.symbol, Symbol('Foo'));
265
- expectWarningInDevelopment(PropTypes.symbol.isRequired, 0);
266
- expectWarningInDevelopment(PropTypes.symbol.isRequired, Symbol('Foo'));
267
- expectWarningInDevelopment(PropTypes.symbol.isRequired, null);
268
- expectWarningInDevelopment(PropTypes.symbol.isRequired, undefined);
269
- expectWarningInDevelopment(PropTypes.object, '');
270
- expectWarningInDevelopment(PropTypes.object, {foo: 'bar'});
271
- expectWarningInDevelopment(PropTypes.object.isRequired, '');
272
- expectWarningInDevelopment(PropTypes.object.isRequired, {foo: 'bar'});
273
- expectWarningInDevelopment(PropTypes.object.isRequired, null);
274
- expectWarningInDevelopment(PropTypes.object.isRequired, undefined);
234
+ expectThrowInDevelopment(PropTypes.array, /please/);
235
+ expectThrowInDevelopment(PropTypes.array, []);
236
+ expectThrowInDevelopment(PropTypes.array.isRequired, /please/);
237
+ expectThrowInDevelopment(PropTypes.array.isRequired, []);
238
+ expectThrowInDevelopment(PropTypes.array.isRequired, null);
239
+ expectThrowInDevelopment(PropTypes.array.isRequired, undefined);
240
+ expectThrowInDevelopment(PropTypes.bool, []);
241
+ expectThrowInDevelopment(PropTypes.bool, true);
242
+ expectThrowInDevelopment(PropTypes.bool.isRequired, []);
243
+ expectThrowInDevelopment(PropTypes.bool.isRequired, true);
244
+ expectThrowInDevelopment(PropTypes.bool.isRequired, null);
245
+ expectThrowInDevelopment(PropTypes.bool.isRequired, undefined);
246
+ expectThrowInDevelopment(PropTypes.func, false);
247
+ expectThrowInDevelopment(PropTypes.func, function() {});
248
+ expectThrowInDevelopment(PropTypes.func.isRequired, false);
249
+ expectThrowInDevelopment(PropTypes.func.isRequired, function() {});
250
+ expectThrowInDevelopment(PropTypes.func.isRequired, null);
251
+ expectThrowInDevelopment(PropTypes.func.isRequired, undefined);
252
+ expectThrowInDevelopment(PropTypes.number, function() {});
253
+ expectThrowInDevelopment(PropTypes.number, 42);
254
+ expectThrowInDevelopment(PropTypes.number.isRequired, function() {});
255
+ expectThrowInDevelopment(PropTypes.number.isRequired, 42);
256
+ expectThrowInDevelopment(PropTypes.number.isRequired, null);
257
+ expectThrowInDevelopment(PropTypes.number.isRequired, undefined);
258
+ expectThrowInDevelopment(PropTypes.string, 0);
259
+ expectThrowInDevelopment(PropTypes.string, 'foo');
260
+ expectThrowInDevelopment(PropTypes.string.isRequired, 0);
261
+ expectThrowInDevelopment(PropTypes.string.isRequired, 'foo');
262
+ expectThrowInDevelopment(PropTypes.string.isRequired, null);
263
+ expectThrowInDevelopment(PropTypes.string.isRequired, undefined);
264
+ expectThrowInDevelopment(PropTypes.symbol, 0);
265
+ expectThrowInDevelopment(PropTypes.symbol, Symbol('Foo'));
266
+ expectThrowInDevelopment(PropTypes.symbol.isRequired, 0);
267
+ expectThrowInDevelopment(PropTypes.symbol.isRequired, Symbol('Foo'));
268
+ expectThrowInDevelopment(PropTypes.symbol.isRequired, null);
269
+ expectThrowInDevelopment(PropTypes.symbol.isRequired, undefined);
270
+ expectThrowInDevelopment(PropTypes.object, '');
271
+ expectThrowInDevelopment(PropTypes.object, {foo: 'bar'});
272
+ expectThrowInDevelopment(PropTypes.object.isRequired, '');
273
+ expectThrowInDevelopment(PropTypes.object.isRequired, {foo: 'bar'});
274
+ expectThrowInDevelopment(PropTypes.object.isRequired, null);
275
+ expectThrowInDevelopment(PropTypes.object.isRequired, undefined);
276
});
277
});
278
@@ -292,11 +293,11 @@ describe('ReactPropTypes', () => {
293
typeCheckFailRequiredValues(PropTypes.any.isRequired);
294
});
295
295
- it('should warn if called manually in development', () => {
296
+ it('should throw if called manually in development', () => {
297
spyOn(console, 'error');
297
- expectWarningInDevelopment(PropTypes.any, null);
298
- expectWarningInDevelopment(PropTypes.any.isRequired, null);
299
- expectWarningInDevelopment(PropTypes.any.isRequired, undefined);
298
+ expectThrowInDevelopment(PropTypes.any, null);
299
+ expectThrowInDevelopment(PropTypes.any.isRequired, null);
300
+ expectThrowInDevelopment(PropTypes.any.isRequired, undefined);
301
});
302
});
303
@@ -388,25 +389,25 @@ describe('ReactPropTypes', () => {
389
);
390
});
391
391
- it('should warn if called manually in development', () => {
392
+ it('should throw if called manually in development', () => {
393
spyOn(console, 'error');
393
- expectWarningInDevelopment(PropTypes.arrayOf({foo: PropTypes.string}), {
394
+ expectThrowInDevelopment(PropTypes.arrayOf({foo: PropTypes.string}), {
395
foo: 'bar',
396
});
396
- expectWarningInDevelopment(PropTypes.arrayOf(PropTypes.number), [
397
+ expectThrowInDevelopment(PropTypes.arrayOf(PropTypes.number), [
398
1,
399
2,
400
'b',
401
]);
401
- expectWarningInDevelopment(PropTypes.arrayOf(PropTypes.number), {
402
+ expectThrowInDevelopment(PropTypes.arrayOf(PropTypes.number), {
403
'0': 'maybe-array',
404
length: 1,
405
});
405
- expectWarningInDevelopment(
406
+ expectThrowInDevelopment(
407
PropTypes.arrayOf(PropTypes.number).isRequired,
408
null,
409
);
409
- expectWarningInDevelopment(
410
+ expectThrowInDevelopment(
411
PropTypes.arrayOf(PropTypes.number).isRequired,
412
undefined,
413
);
@@ -484,15 +485,15 @@ describe('ReactPropTypes', () => {
485
typeCheckFailRequiredValues(PropTypes.element.isRequired);
486
});
487
487
- it('should warn if called manually in development', () => {
488
+ it('should throw if called manually in development', () => {
489
spyOn(console, 'error');
489
- expectWarningInDevelopment(PropTypes.element, [<div />, <div />]);
490
- expectWarningInDevelopment(PropTypes.element, <div />);
491
- expectWarningInDevelopment(PropTypes.element, 123);
492
- expectWarningInDevelopment(PropTypes.element, 'foo');
493
- expectWarningInDevelopment(PropTypes.element, false);
494
- expectWarningInDevelopment(PropTypes.element.isRequired, null);
495
- expectWarningInDevelopment(PropTypes.element.isRequired, undefined);
490
+ expectThrowInDevelopment(PropTypes.element, [<div />, <div />]);
491
+ expectThrowInDevelopment(PropTypes.element, <div />);
492
+ expectThrowInDevelopment(PropTypes.element, 123);
493
+ expectThrowInDevelopment(PropTypes.element, 'foo');
494
+ expectThrowInDevelopment(PropTypes.element, false);
495
+ expectThrowInDevelopment(PropTypes.element.isRequired, null);
496
+ expectThrowInDevelopment(PropTypes.element.isRequired, undefined);
497
});
498
});
499
@@ -583,12 +584,12 @@ describe('ReactPropTypes', () => {
584
typeCheckFailRequiredValues(PropTypes.instanceOf(String).isRequired);
585
});
586
586
- it('should warn if called manually in development', () => {
587
+ it('should throw if called manually in development', () => {
588
spyOn(console, 'error');
588
- expectWarningInDevelopment(PropTypes.instanceOf(Date), {});
589
- expectWarningInDevelopment(PropTypes.instanceOf(Date), new Date());
590
- expectWarningInDevelopment(PropTypes.instanceOf(Date).isRequired, {});
591
- expectWarningInDevelopment(
589
+ expectThrowInDevelopment(PropTypes.instanceOf(Date), {});
590
+ expectThrowInDevelopment(PropTypes.instanceOf(Date), new Date());
591
+ expectThrowInDevelopment(PropTypes.instanceOf(Date).isRequired, {});
592
+ expectThrowInDevelopment(
593
PropTypes.instanceOf(Date).isRequired,
594
new Date(),
595
);
@@ -680,13 +681,13 @@ describe('ReactPropTypes', () => {
681
typeCheckPass(PropTypes.node.isRequired, []);
682
});
683
683
- it('should warn if called manually in development', () => {
684
+ it('should throw if called manually in development', () => {
685
spyOn(console, 'error');
685
- expectWarningInDevelopment(PropTypes.node, 'node');
686
- expectWarningInDevelopment(PropTypes.node, {});
687
- expectWarningInDevelopment(PropTypes.node.isRequired, 'node');
688
- expectWarningInDevelopment(PropTypes.node.isRequired, undefined);
689
- expectWarningInDevelopment(PropTypes.node.isRequired, undefined);
686
+ expectThrowInDevelopment(PropTypes.node, 'node');
687
+ expectThrowInDevelopment(PropTypes.node, {});
688
+ expectThrowInDevelopment(PropTypes.node.isRequired, 'node');
689
+ expectThrowInDevelopment(PropTypes.node.isRequired, undefined);
690
+ expectThrowInDevelopment(PropTypes.node.isRequired, undefined);
691
});
692
});
693
@@ -795,22 +796,19 @@ describe('ReactPropTypes', () => {
796
);
797
});
798
798
- it('should warn if called manually in development', () => {
799
+ it('should throw if called manually in development', () => {
800
spyOn(console, 'error');
800
- expectWarningInDevelopment(PropTypes.objectOf({foo: PropTypes.string}), {
801
+ expectThrowInDevelopment(PropTypes.objectOf({foo: PropTypes.string}), {
802
foo: 'bar',
803
});
803
- expectWarningInDevelopment(PropTypes.objectOf(PropTypes.number), {
804
+ expectThrowInDevelopment(PropTypes.objectOf(PropTypes.number), {
805
a: 1,
806
b: 2,
807
c: 'b',
808
});
808
- expectWarningInDevelopment(PropTypes.objectOf(PropTypes.number), [1, 2]);
809
- expectWarningInDevelopment(PropTypes.objectOf(PropTypes.number), null);
810
- expectWarningInDevelopment(
811
- PropTypes.objectOf(PropTypes.number),
812
- undefined,
813
- );
809
+ expectThrowInDevelopment(PropTypes.objectOf(PropTypes.number), [1, 2]);
810
+ expectThrowInDevelopment(PropTypes.objectOf(PropTypes.number), null);
811
+ expectThrowInDevelopment(PropTypes.objectOf(PropTypes.number), undefined);
812
});
813
});
814
@@ -870,11 +868,11 @@ describe('ReactPropTypes', () => {
868
typeCheckFailRequiredValues(PropTypes.oneOf(['red', 'blue']).isRequired);
869
});
870
873
- it('should warn if called manually in development', () => {
871
+ it('should throw if called manually in development', () => {
872
spyOn(console, 'error');
875
- expectWarningInDevelopment(PropTypes.oneOf(['red', 'blue']), true);
876
- expectWarningInDevelopment(PropTypes.oneOf(['red', 'blue']), null);
877
- expectWarningInDevelopment(PropTypes.oneOf(['red', 'blue']), undefined);
873
+ expectThrowInDevelopment(PropTypes.oneOf(['red', 'blue']), true);
874
+ expectThrowInDevelopment(PropTypes.oneOf(['red', 'blue']), null);
875
+ expectThrowInDevelopment(PropTypes.oneOf(['red', 'blue']), undefined);
876
});
877
});
878
@@ -941,17 +939,17 @@ describe('ReactPropTypes', () => {
939
);
940
});
941
944
- it('should warn if called manually in development', () => {
942
+ it('should throw if called manually in development', () => {
943
spyOn(console, 'error');
946
- expectWarningInDevelopment(
944
+ expectThrowInDevelopment(
945
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
946
[],
947
);
950
- expectWarningInDevelopment(
948
+ expectThrowInDevelopment(
949
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
950
null,
951
);
954
- expectWarningInDevelopment(
952
+ expectThrowInDevelopment(
953
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
954
undefined,
955
);
@@ -1039,21 +1037,21 @@ describe('ReactPropTypes', () => {
1037
);
1038
});
1039
1042
- it('should warn if called manually in development', () => {
1040
+ it('should throw if called manually in development', () => {
1041
spyOn(console, 'error');
1044
- expectWarningInDevelopment(PropTypes.shape({}), 'some string');
1045
- expectWarningInDevelopment(PropTypes.shape({foo: PropTypes.number}), {
1042
+ expectThrowInDevelopment(PropTypes.shape({}), 'some string');
1043
+ expectThrowInDevelopment(PropTypes.shape({foo: PropTypes.number}), {
1044
foo: 42,
1045
});
1048
- expectWarningInDevelopment(
1046
+ expectThrowInDevelopment(
1047
PropTypes.shape({key: PropTypes.number}).isRequired,
1048
null,
1049
);
1052
- expectWarningInDevelopment(
1050
+ expectThrowInDevelopment(
1051
PropTypes.shape({key: PropTypes.number}).isRequired,
1052
undefined,
1053
);
1056
- expectWarningInDevelopment(PropTypes.element, <div />);
1054
+ expectThrowInDevelopment(PropTypes.element, <div />);
1055
});
1056
});
1057