@samitouri / QOS-React / commits / bef723e47f

Remove ReactPropTypeLocationNames module

ReactPropTypeLocationNames was a map of location identifiers to location display names, for use in warnings. But in practice, this did nothing except rename "childContext" to "child context." Not worth it, IMO. Since we are going to add an API for running prop type checks manually, we need the ability to support arbitrary prop type locations. So each place that used to accept a ReactPropTypeLocation now just accepts a string.

Andrew Clark committed Feb 14, 2017 at 14:53 UTC bef723e47f09f1136d6a94e4db81fb1ca59cb359
9 files changed +23 -91
src/isomorphic/classic/__tests__/ReactContextValidator-test.js
+2 -2
@@ -261,7 +261,7 @@ describe('ReactContextValidator', () => {
261 ReactTestUtils.renderIntoDocument(<Component testContext={{bar: 123}} />);
262 expectDev(console.error.calls.count()).toBe(1);
263 expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
264 - 'Warning: Failed childContext type: ' +
264 + 'Warning: Failed child context type: ' +
265 'The child context `foo` is marked as required in `Component`, but its ' +
266 'value is `undefined`.\n' +
267 ' in Component (at **)'
@@ -271,7 +271,7 @@ describe('ReactContextValidator', () => {
271
272 expectDev(console.error.calls.count()).toBe(2);
273 expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
274 - 'Warning: Failed childContext type: ' +
274 + 'Warning: Failed child context type: ' +
275 'Invalid child context `foo` of type `number` ' +
276 'supplied to `Component`, expected `string`.\n' +
277 ' in Component (at **)'
src/isomorphic/classic/class/ReactClass.js
+3 -6
@@ -13,7 +13,6 @@
13
14 var ReactBaseClasses = require('ReactBaseClasses');
15 var ReactElement = require('ReactElement');
16 -var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames');
16 var ReactNoopUpdateQueue = require('ReactNoopUpdateQueue');
17
18 var emptyObject = require('emptyObject');
@@ -22,8 +21,6 @@ var warning = require('warning');
21
22 var ReactComponent = ReactBaseClasses.Component;
23
25 -import type { ReactPropTypeLocations } from 'ReactPropTypeLocations';
26 -
24 var MIXINS_KEY = 'mixins';
25
26 // Helper function to allow the creation of anonymous functions which do not
@@ -330,7 +327,7 @@ var RESERVED_SPEC_KEYS = {
327 validateTypeDef(
328 Constructor,
329 childContextTypes,
333 - 'childContext'
330 + 'child context'
331 );
332 }
333 Constructor.childContextTypes = Object.assign(
@@ -390,7 +387,7 @@ var RESERVED_SPEC_KEYS = {
387 function validateTypeDef(
388 Constructor,
389 typeDef,
393 - location: ReactPropTypeLocations,
390 + location: string,
391 ) {
392 for (var propName in typeDef) {
393 if (typeDef.hasOwnProperty(propName)) {
@@ -401,7 +398,7 @@ function validateTypeDef(
398 '%s: %s type `%s` is invalid; it must be a function, usually from ' +
399 'React.PropTypes.',
400 Constructor.displayName || 'ReactClass',
404 - ReactPropTypeLocationNames[location],
401 + location,
402 propName
403 );
404 }
src/isomorphic/classic/types/ReactPropTypes.js
+11 -22
@@ -12,7 +12,6 @@
12 'use strict';
13
14 var ReactElement = require('ReactElement');
15 -var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames');
15 var ReactPropTypesSecret = require('ReactPropTypesSecret');
16
17 var emptyFunction = require('emptyFunction');
@@ -192,16 +191,15 @@ function createChainableTypeChecker(validate) {
191 }
192 }
193 if (props[propName] == null) {
195 - var locationName = ReactPropTypeLocationNames[location];
194 if (isRequired) {
195 if (props[propName] === null) {
196 return new PropTypeError(
199 - `The ${locationName} \`${propFullName}\` is marked as required ` +
197 + `The ${location} \`${propFullName}\` is marked as required ` +
198 `in \`${componentName}\`, but its value is \`null\`.`
199 );
200 }
201 return new PropTypeError(
204 - `The ${locationName} \`${propFullName}\` is marked as required in ` +
202 + `The ${location} \`${propFullName}\` is marked as required in ` +
203 `\`${componentName}\`, but its value is \`undefined\`.`
204 );
205 }
@@ -235,14 +233,13 @@ function createPrimitiveTypeChecker(expectedType) {
233 var propValue = props[propName];
234 var propType = getPropType(propValue);
235 if (propType !== expectedType) {
238 - var locationName = ReactPropTypeLocationNames[location];
236 // `propValue` being instance of, say, date/regexp, pass the 'object'
237 // check, but we can offer a more precise error message here rather than
238 // 'of type `object`'.
239 var preciseType = getPreciseType(propValue);
240
241 return new PropTypeError(
245 - `Invalid ${locationName} \`${propFullName}\` of type ` +
242 + `Invalid ${location} \`${propFullName}\` of type ` +
243 `\`${preciseType}\` supplied to \`${componentName}\`, expected ` +
244 `\`${expectedType}\`.`
245 );
@@ -265,10 +262,9 @@ function createArrayOfTypeChecker(typeChecker) {
262 }
263 var propValue = props[propName];
264 if (!Array.isArray(propValue)) {
268 - var locationName = ReactPropTypeLocationNames[location];
265 var propType = getPropType(propValue);
266 return new PropTypeError(
271 - `Invalid ${locationName} \`${propFullName}\` of type ` +
267 + `Invalid ${location} \`${propFullName}\` of type ` +
268 `\`${propType}\` supplied to \`${componentName}\`, expected an array.`
269 );
270 }
@@ -294,10 +290,9 @@ function createElementTypeChecker() {
290 function validate(props, propName, componentName, location, propFullName) {
291 var propValue = props[propName];
292 if (!ReactElement.isValidElement(propValue)) {
297 - var locationName = ReactPropTypeLocationNames[location];
293 var propType = getPropType(propValue);
294 return new PropTypeError(
300 - `Invalid ${locationName} \`${propFullName}\` of type ` +
295 + `Invalid ${location} \`${propFullName}\` of type ` +
296 `\`${propType}\` supplied to \`${componentName}\`, expected a single ReactElement.`
297 );
298 }
@@ -309,11 +304,10 @@ function createElementTypeChecker() {
304 function createInstanceTypeChecker(expectedClass) {
305 function validate(props, propName, componentName, location, propFullName) {
306 if (!(props[propName] instanceof expectedClass)) {
312 - var locationName = ReactPropTypeLocationNames[location];
307 var expectedClassName = expectedClass.name || ANONYMOUS;
308 var actualClassName = getClassName(props[propName]);
309 return new PropTypeError(
316 - `Invalid ${locationName} \`${propFullName}\` of type ` +
310 + `Invalid ${location} \`${propFullName}\` of type ` +
311 `\`${actualClassName}\` supplied to \`${componentName}\`, expected ` +
312 `instance of \`${expectedClassName}\`.`
313 );
@@ -337,10 +331,9 @@ function createEnumTypeChecker(expectedValues) {
331 }
332 }
333
340 - var locationName = ReactPropTypeLocationNames[location];
334 var valuesString = JSON.stringify(expectedValues);
335 return new PropTypeError(
343 - `Invalid ${locationName} \`${propFullName}\` of value \`${propValue}\` ` +
336 + `Invalid ${location} \`${propFullName}\` of value \`${propValue}\` ` +
337 `supplied to \`${componentName}\`, expected one of ${valuesString}.`
338 );
339 }
@@ -357,9 +350,8 @@ function createObjectOfTypeChecker(typeChecker) {
350 var propValue = props[propName];
351 var propType = getPropType(propValue);
352 if (propType !== 'object') {
360 - var locationName = ReactPropTypeLocationNames[location];
353 return new PropTypeError(
362 - `Invalid ${locationName} \`${propFullName}\` of type ` +
354 + `Invalid ${location} \`${propFullName}\` of type ` +
355 `\`${propType}\` supplied to \`${componentName}\`, expected an object.`
356 );
357 }
@@ -406,9 +398,8 @@ function createUnionTypeChecker(arrayOfTypeCheckers) {
398 }
399 }
400
409 - var locationName = ReactPropTypeLocationNames[location];
401 return new PropTypeError(
411 - `Invalid ${locationName} \`${propFullName}\` supplied to ` +
402 + `Invalid ${location} \`${propFullName}\` supplied to ` +
403 `\`${componentName}\`.`
404 );
405 }
@@ -418,9 +409,8 @@ function createUnionTypeChecker(arrayOfTypeCheckers) {
409 function createNodeChecker() {
410 function validate(props, propName, componentName, location, propFullName) {
411 if (!isNode(props[propName])) {
421 - var locationName = ReactPropTypeLocationNames[location];
412 return new PropTypeError(
423 - `Invalid ${locationName} \`${propFullName}\` supplied to ` +
413 + `Invalid ${location} \`${propFullName}\` supplied to ` +
414 `\`${componentName}\`, expected a ReactNode.`
415 );
416 }
@@ -434,9 +424,8 @@ function createShapeTypeChecker(shapeTypes) {
424 var propValue = props[propName];
425 var propType = getPropType(propValue);
426 if (propType !== 'object') {
437 - var locationName = ReactPropTypeLocationNames[location];
427 return new PropTypeError(
439 - `Invalid ${locationName} \`${propFullName}\` of type \`${propType}\` ` +
428 + `Invalid ${location} \`${propFullName}\` of type \`${propType}\` ` +
429 `supplied to \`${componentName}\`, expected \`object\`.`
430 );
431 }
src/isomorphic/classic/types/__tests__/ReactPropTypesProduction-test.js
+1 -3
@@ -14,7 +14,6 @@
14 describe('ReactPropTypesProduction', function() {
15 var PropTypes;
16 var React;
17 - var ReactPropTypeLocations;
17 var ReactTestUtils;
18 var oldProcess;
19
@@ -32,7 +31,6 @@ describe('ReactPropTypesProduction', function() {
31 jest.resetModules();
32 PropTypes = require('ReactPropTypes');
33 React = require('React');
35 - ReactPropTypeLocations = require('ReactPropTypeLocations');
34 ReactTestUtils = require('ReactTestUtils');
35 });
36
@@ -48,7 +46,7 @@ describe('ReactPropTypesProduction', function() {
46 props,
47 'testProp',
48 'testComponent',
51 - ReactPropTypeLocations.prop
49 + 'prop'
50 );
51 }).toThrowError(
52 'React.PropTypes type checking code is stripped in production.'
src/renderers/shared/fiber/ReactFiberContext.js
+1 -1
@@ -182,7 +182,7 @@ function processChildContext(fiber : Fiber, parentContext : Object, isReconcilin
182 // assume anything about the given fiber. We won't pass it down if we aren't sure.
183 // TODO: remove this hack when we delete unstable_renderSubtree in Fiber.
184 const workInProgress = isReconciling ? fiber : null;
185 - checkReactTypeSpec(childContextTypes, childContext, 'childContext', name, null, workInProgress);
185 + checkReactTypeSpec(childContextTypes, childContext, 'child context', name, null, workInProgress);
186 }
187 return {...parentContext, ...childContext};
188 }
src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
+2 -4
@@ -33,8 +33,6 @@ var shallowEqual = require('shallowEqual');
33 var shouldUpdateReactComponent = require('shouldUpdateReactComponent');
34 var warning = require('warning');
35
36 -import type { ReactPropTypeLocations } from 'ReactPropTypeLocations';
37 -
36 function StatelessComponent(Component) {
37 }
38 StatelessComponent.prototype.render = function() {
@@ -687,7 +685,7 @@ var ReactCompositeComponent = {
685 this._checkContextTypes(
686 Component.childContextTypes,
687 childContext,
690 - 'childContext'
688 + 'child context'
689 );
690 }
691 for (var name in childContext) {
@@ -730,7 +728,7 @@ var ReactCompositeComponent = {
728 _checkContextTypes: function(
729 typeSpecs,
730 values,
733 - location: ReactPropTypeLocations,
731 + location: string,
732 ) {
733 if (__DEV__) {
734 checkReactTypeSpec(
src/shared/types/ReactPropTypeLocationNames.js deleted
-29
@@ -1,29 +0,0 @@
1 -/**
2 - * Copyright 2013-present, 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 this source tree. An additional grant
7 - * of patent rights can be found in the PATENTS file in the same directory.
8 - *
9 - * @flow
10 - * @providesModule ReactPropTypeLocationNames
11 - */
12 -
13 -'use strict';
14 -
15 -import type { ReactPropTypeLocations } from 'ReactPropTypeLocations';
16 -
17 -type NamesType = {[key: ReactPropTypeLocations]: string};
18 -
19 -var ReactPropTypeLocationNames: NamesType = {};
20 -
21 -if (__DEV__) {
22 - ReactPropTypeLocationNames = {
23 - prop: 'prop',
24 - context: 'context',
25 - childContext: 'child context',
26 - };
27 -}
28 -
29 -module.exports = ReactPropTypeLocationNames;
src/shared/types/ReactPropTypeLocations.js deleted
-18
@@ -1,18 +0,0 @@
1 -/**
2 - * Copyright 2013-present, 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 this source tree. An additional grant
7 - * of patent rights can be found in the PATENTS file in the same directory.
8 - *
9 - * @flow
10 - * @providesModule ReactPropTypeLocations
11 - */
12 -
13 -'use strict';
14 -
15 -export type ReactPropTypeLocations =
16 - 'prop' |
17 - 'context' |
18 - 'childContext';
src/shared/types/checkReactTypeSpec.js
+3 -6
@@ -11,14 +11,11 @@
11
12 'use strict';
13
14 -var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames');
14 var ReactPropTypesSecret = require('ReactPropTypesSecret');
15
16 var invariant = require('invariant');
17 var warning = require('warning');
18
20 -import type { ReactPropTypeLocations } from 'ReactPropTypeLocations';
21 -
19 var ReactComponentTreeHook;
20
21 if (
@@ -51,7 +48,7 @@ var loggedTypeFailures = {};
48 function checkReactTypeSpec(
49 typeSpecs,
50 values,
54 - location: ReactPropTypeLocations,
51 + location: string,
52 componentName,
53 element,
54 // It is only safe to pass fiber if it is the work-in-progress version, and
@@ -72,7 +69,7 @@ function checkReactTypeSpec(
69 '%s: %s type `%s` is invalid; it must be a function, usually from ' +
70 'React.PropTypes.',
71 componentName || 'React class',
75 - ReactPropTypeLocationNames[location],
72 + location,
73 typeSpecName
74 );
75 error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
@@ -87,7 +84,7 @@ function checkReactTypeSpec(
84 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
85 'shape all require an argument).',
86 componentName || 'React class',
90 - ReactPropTypeLocationNames[location],
87 + location,
88 typeSpecName,
89 typeof error
90 );