diff --git a/src/isomorphic/classic/__tests__/ReactContextValidator-test.js b/src/isomorphic/classic/__tests__/ReactContextValidator-test.js index 08582a200d..a5a04430aa 100644 --- a/src/isomorphic/classic/__tests__/ReactContextValidator-test.js +++ b/src/isomorphic/classic/__tests__/ReactContextValidator-test.js @@ -261,7 +261,7 @@ describe('ReactContextValidator', () => { ReactTestUtils.renderIntoDocument(); expectDev(console.error.calls.count()).toBe(1); expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe( - 'Warning: Failed childContext type: ' + + 'Warning: Failed child context type: ' + 'The child context `foo` is marked as required in `Component`, but its ' + 'value is `undefined`.\n' + ' in Component (at **)' @@ -271,7 +271,7 @@ describe('ReactContextValidator', () => { expectDev(console.error.calls.count()).toBe(2); expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe( - 'Warning: Failed childContext type: ' + + 'Warning: Failed child context type: ' + 'Invalid child context `foo` of type `number` ' + 'supplied to `Component`, expected `string`.\n' + ' in Component (at **)' diff --git a/src/isomorphic/classic/class/ReactClass.js b/src/isomorphic/classic/class/ReactClass.js index bf2f425f8f..a4efdd825a 100644 --- a/src/isomorphic/classic/class/ReactClass.js +++ b/src/isomorphic/classic/class/ReactClass.js @@ -13,7 +13,6 @@ var ReactBaseClasses = require('ReactBaseClasses'); var ReactElement = require('ReactElement'); -var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames'); var ReactNoopUpdateQueue = require('ReactNoopUpdateQueue'); var emptyObject = require('emptyObject'); @@ -22,8 +21,6 @@ var warning = require('warning'); var ReactComponent = ReactBaseClasses.Component; -import type { ReactPropTypeLocations } from 'ReactPropTypeLocations'; - var MIXINS_KEY = 'mixins'; // Helper function to allow the creation of anonymous functions which do not @@ -330,7 +327,7 @@ var RESERVED_SPEC_KEYS = { validateTypeDef( Constructor, childContextTypes, - 'childContext' + 'child context' ); } Constructor.childContextTypes = Object.assign( @@ -390,7 +387,7 @@ var RESERVED_SPEC_KEYS = { function validateTypeDef( Constructor, typeDef, - location: ReactPropTypeLocations, + location: string, ) { for (var propName in typeDef) { if (typeDef.hasOwnProperty(propName)) { @@ -401,7 +398,7 @@ function validateTypeDef( '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', Constructor.displayName || 'ReactClass', - ReactPropTypeLocationNames[location], + location, propName ); } diff --git a/src/isomorphic/classic/types/ReactPropTypes.js b/src/isomorphic/classic/types/ReactPropTypes.js index dcd0dbc82a..936de6dc75 100644 --- a/src/isomorphic/classic/types/ReactPropTypes.js +++ b/src/isomorphic/classic/types/ReactPropTypes.js @@ -12,7 +12,6 @@ 'use strict'; var ReactElement = require('ReactElement'); -var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames'); var ReactPropTypesSecret = require('ReactPropTypesSecret'); var emptyFunction = require('emptyFunction'); @@ -192,16 +191,15 @@ function createChainableTypeChecker(validate) { } } if (props[propName] == null) { - var locationName = ReactPropTypeLocationNames[location]; if (isRequired) { if (props[propName] === null) { return new PropTypeError( - `The ${locationName} \`${propFullName}\` is marked as required ` + + `The ${location} \`${propFullName}\` is marked as required ` + `in \`${componentName}\`, but its value is \`null\`.` ); } return new PropTypeError( - `The ${locationName} \`${propFullName}\` is marked as required in ` + + `The ${location} \`${propFullName}\` is marked as required in ` + `\`${componentName}\`, but its value is \`undefined\`.` ); } @@ -235,14 +233,13 @@ function createPrimitiveTypeChecker(expectedType) { var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== expectedType) { - var locationName = ReactPropTypeLocationNames[location]; // `propValue` being instance of, say, date/regexp, pass the 'object' // check, but we can offer a more precise error message here rather than // 'of type `object`'. var preciseType = getPreciseType(propValue); return new PropTypeError( - `Invalid ${locationName} \`${propFullName}\` of type ` + + `Invalid ${location} \`${propFullName}\` of type ` + `\`${preciseType}\` supplied to \`${componentName}\`, expected ` + `\`${expectedType}\`.` ); @@ -265,10 +262,9 @@ function createArrayOfTypeChecker(typeChecker) { } var propValue = props[propName]; if (!Array.isArray(propValue)) { - var locationName = ReactPropTypeLocationNames[location]; var propType = getPropType(propValue); return new PropTypeError( - `Invalid ${locationName} \`${propFullName}\` of type ` + + `Invalid ${location} \`${propFullName}\` of type ` + `\`${propType}\` supplied to \`${componentName}\`, expected an array.` ); } @@ -294,10 +290,9 @@ function createElementTypeChecker() { function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; if (!ReactElement.isValidElement(propValue)) { - var locationName = ReactPropTypeLocationNames[location]; var propType = getPropType(propValue); return new PropTypeError( - `Invalid ${locationName} \`${propFullName}\` of type ` + + `Invalid ${location} \`${propFullName}\` of type ` + `\`${propType}\` supplied to \`${componentName}\`, expected a single ReactElement.` ); } @@ -309,11 +304,10 @@ function createElementTypeChecker() { function createInstanceTypeChecker(expectedClass) { function validate(props, propName, componentName, location, propFullName) { if (!(props[propName] instanceof expectedClass)) { - var locationName = ReactPropTypeLocationNames[location]; var expectedClassName = expectedClass.name || ANONYMOUS; var actualClassName = getClassName(props[propName]); return new PropTypeError( - `Invalid ${locationName} \`${propFullName}\` of type ` + + `Invalid ${location} \`${propFullName}\` of type ` + `\`${actualClassName}\` supplied to \`${componentName}\`, expected ` + `instance of \`${expectedClassName}\`.` ); @@ -337,10 +331,9 @@ function createEnumTypeChecker(expectedValues) { } } - var locationName = ReactPropTypeLocationNames[location]; var valuesString = JSON.stringify(expectedValues); return new PropTypeError( - `Invalid ${locationName} \`${propFullName}\` of value \`${propValue}\` ` + + `Invalid ${location} \`${propFullName}\` of value \`${propValue}\` ` + `supplied to \`${componentName}\`, expected one of ${valuesString}.` ); } @@ -357,9 +350,8 @@ function createObjectOfTypeChecker(typeChecker) { var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== 'object') { - var locationName = ReactPropTypeLocationNames[location]; return new PropTypeError( - `Invalid ${locationName} \`${propFullName}\` of type ` + + `Invalid ${location} \`${propFullName}\` of type ` + `\`${propType}\` supplied to \`${componentName}\`, expected an object.` ); } @@ -406,9 +398,8 @@ function createUnionTypeChecker(arrayOfTypeCheckers) { } } - var locationName = ReactPropTypeLocationNames[location]; return new PropTypeError( - `Invalid ${locationName} \`${propFullName}\` supplied to ` + + `Invalid ${location} \`${propFullName}\` supplied to ` + `\`${componentName}\`.` ); } @@ -418,9 +409,8 @@ function createUnionTypeChecker(arrayOfTypeCheckers) { function createNodeChecker() { function validate(props, propName, componentName, location, propFullName) { if (!isNode(props[propName])) { - var locationName = ReactPropTypeLocationNames[location]; return new PropTypeError( - `Invalid ${locationName} \`${propFullName}\` supplied to ` + + `Invalid ${location} \`${propFullName}\` supplied to ` + `\`${componentName}\`, expected a ReactNode.` ); } @@ -434,9 +424,8 @@ function createShapeTypeChecker(shapeTypes) { var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== 'object') { - var locationName = ReactPropTypeLocationNames[location]; return new PropTypeError( - `Invalid ${locationName} \`${propFullName}\` of type \`${propType}\` ` + + `Invalid ${location} \`${propFullName}\` of type \`${propType}\` ` + `supplied to \`${componentName}\`, expected \`object\`.` ); } diff --git a/src/isomorphic/classic/types/__tests__/ReactPropTypesProduction-test.js b/src/isomorphic/classic/types/__tests__/ReactPropTypesProduction-test.js index 076c163934..8e6a868c9f 100644 --- a/src/isomorphic/classic/types/__tests__/ReactPropTypesProduction-test.js +++ b/src/isomorphic/classic/types/__tests__/ReactPropTypesProduction-test.js @@ -14,7 +14,6 @@ describe('ReactPropTypesProduction', function() { var PropTypes; var React; - var ReactPropTypeLocations; var ReactTestUtils; var oldProcess; @@ -32,7 +31,6 @@ describe('ReactPropTypesProduction', function() { jest.resetModules(); PropTypes = require('ReactPropTypes'); React = require('React'); - ReactPropTypeLocations = require('ReactPropTypeLocations'); ReactTestUtils = require('ReactTestUtils'); }); @@ -48,7 +46,7 @@ describe('ReactPropTypesProduction', function() { props, 'testProp', 'testComponent', - ReactPropTypeLocations.prop + 'prop' ); }).toThrowError( 'React.PropTypes type checking code is stripped in production.' diff --git a/src/renderers/shared/fiber/ReactFiberContext.js b/src/renderers/shared/fiber/ReactFiberContext.js index 8b7383458b..537c04fb4d 100644 --- a/src/renderers/shared/fiber/ReactFiberContext.js +++ b/src/renderers/shared/fiber/ReactFiberContext.js @@ -182,7 +182,7 @@ function processChildContext(fiber : Fiber, parentContext : Object, isReconcilin // assume anything about the given fiber. We won't pass it down if we aren't sure. // TODO: remove this hack when we delete unstable_renderSubtree in Fiber. const workInProgress = isReconciling ? fiber : null; - checkReactTypeSpec(childContextTypes, childContext, 'childContext', name, null, workInProgress); + checkReactTypeSpec(childContextTypes, childContext, 'child context', name, null, workInProgress); } return {...parentContext, ...childContext}; } diff --git a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js index 9a572a8f6f..3bfb0ec08e 100644 --- a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js +++ b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js @@ -33,8 +33,6 @@ var shallowEqual = require('shallowEqual'); var shouldUpdateReactComponent = require('shouldUpdateReactComponent'); var warning = require('warning'); -import type { ReactPropTypeLocations } from 'ReactPropTypeLocations'; - function StatelessComponent(Component) { } StatelessComponent.prototype.render = function() { @@ -687,7 +685,7 @@ var ReactCompositeComponent = { this._checkContextTypes( Component.childContextTypes, childContext, - 'childContext' + 'child context' ); } for (var name in childContext) { @@ -730,7 +728,7 @@ var ReactCompositeComponent = { _checkContextTypes: function( typeSpecs, values, - location: ReactPropTypeLocations, + location: string, ) { if (__DEV__) { checkReactTypeSpec( diff --git a/src/shared/types/ReactPropTypeLocationNames.js b/src/shared/types/ReactPropTypeLocationNames.js deleted file mode 100644 index 1b36b04cc8..0000000000 --- a/src/shared/types/ReactPropTypeLocationNames.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @flow - * @providesModule ReactPropTypeLocationNames - */ - -'use strict'; - -import type { ReactPropTypeLocations } from 'ReactPropTypeLocations'; - -type NamesType = {[key: ReactPropTypeLocations]: string}; - -var ReactPropTypeLocationNames: NamesType = {}; - -if (__DEV__) { - ReactPropTypeLocationNames = { - prop: 'prop', - context: 'context', - childContext: 'child context', - }; -} - -module.exports = ReactPropTypeLocationNames; diff --git a/src/shared/types/ReactPropTypeLocations.js b/src/shared/types/ReactPropTypeLocations.js deleted file mode 100644 index a2cb905e19..0000000000 --- a/src/shared/types/ReactPropTypeLocations.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @flow - * @providesModule ReactPropTypeLocations - */ - -'use strict'; - -export type ReactPropTypeLocations = - 'prop' | - 'context' | - 'childContext'; diff --git a/src/shared/types/checkReactTypeSpec.js b/src/shared/types/checkReactTypeSpec.js index e274c3e9f5..acb5032a66 100644 --- a/src/shared/types/checkReactTypeSpec.js +++ b/src/shared/types/checkReactTypeSpec.js @@ -11,14 +11,11 @@ 'use strict'; -var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames'); var ReactPropTypesSecret = require('ReactPropTypesSecret'); var invariant = require('invariant'); var warning = require('warning'); -import type { ReactPropTypeLocations } from 'ReactPropTypeLocations'; - var ReactComponentTreeHook; if ( @@ -51,7 +48,7 @@ var loggedTypeFailures = {}; function checkReactTypeSpec( typeSpecs, values, - location: ReactPropTypeLocations, + location: string, componentName, element, // It is only safe to pass fiber if it is the work-in-progress version, and @@ -72,7 +69,7 @@ function checkReactTypeSpec( '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', componentName || 'React class', - ReactPropTypeLocationNames[location], + location, typeSpecName ); error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret); @@ -87,7 +84,7 @@ function checkReactTypeSpec( 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', - ReactPropTypeLocationNames[location], + location, typeSpecName, typeof error );