From 9da2fd0f7b4a63cc784e35f348e2601f1c0f5cf4 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sun, 23 Oct 2016 21:12:36 +0100 Subject: [PATCH] Revert "Warn if PropType function is called manually (#7132)" This reverts commit e75e8dcbebca63cff2b478d8f7ff58e0a2926465. --- .../link/__tests__/ReactLinkPropTypes-test.js | 5 - .../classic/types/ReactPropTypes.js | 64 +------ .../types/__tests__/ReactPropTypes-test.js | 181 ------------------ .../dom/client/wrappers/LinkedValueUtils.js | 3 - src/shared/types/ReactPropTypesSecret.js | 17 -- src/shared/types/checkReactTypeSpec.js | 3 +- 6 files changed, 8 insertions(+), 265 deletions(-) delete mode 100644 src/shared/types/ReactPropTypesSecret.js diff --git a/src/addons/link/__tests__/ReactLinkPropTypes-test.js b/src/addons/link/__tests__/ReactLinkPropTypes-test.js index 28fd2d87a1788..d4e3a9e5cb36d 100644 --- a/src/addons/link/__tests__/ReactLinkPropTypes-test.js +++ b/src/addons/link/__tests__/ReactLinkPropTypes-test.js @@ -14,7 +14,6 @@ var emptyFunction = require('emptyFunction'); var LinkPropTypes = require('ReactLink').PropTypes; var React = require('React'); -var ReactPropTypesSecret = require('ReactPropTypesSecret'); var invalidMessage = 'Invalid prop `testProp` supplied to `testComponent`.'; var requiredMessage = 'The prop `testProp` is marked as required in ' + @@ -27,8 +26,6 @@ function typeCheckFail(declaration, value, message) { 'testProp', 'testComponent', 'prop', - null, - ReactPropTypesSecret ); expect(error instanceof Error).toBe(true); expect(error.message).toBe(message); @@ -41,8 +38,6 @@ function typeCheckPass(declaration, value) { 'testProp', 'testComponent', 'prop', - null, - ReactPropTypesSecret ); expect(error).toBe(null); } diff --git a/src/isomorphic/classic/types/ReactPropTypes.js b/src/isomorphic/classic/types/ReactPropTypes.js index 49c0654c031bb..15fad747700f8 100644 --- a/src/isomorphic/classic/types/ReactPropTypes.js +++ b/src/isomorphic/classic/types/ReactPropTypes.js @@ -13,7 +13,6 @@ var ReactElement = require('ReactElement'); var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames'); -var ReactPropTypesSecret = require('ReactPropTypesSecret'); var emptyFunction = require('emptyFunction'); var getIteratorFn = require('getIteratorFn'); @@ -153,42 +152,16 @@ function PropTypeError(message) { PropTypeError.prototype = Error.prototype; function createChainableTypeChecker(validate) { - if (__DEV__) { - var manualPropTypeCallCache = {}; - } function checkType( isRequired, props, propName, componentName, location, - propFullName, - secret + propFullName ) { componentName = componentName || ANONYMOUS; propFullName = propFullName || propName; - if (__DEV__) { - if ( - secret !== ReactPropTypesSecret && - typeof console !== 'undefined' - ) { - var cacheKey = `${componentName}:${propName}`; - if (!manualPropTypeCallCache[cacheKey]) { - warning( - false, - 'You are manually calling a React.PropTypes validation ' + - 'function for the `%s` prop on `%s`. This is deprecated ' + - 'and will not work in production with the next major version. ' + - 'You may be seeing this warning due to a third-party PropTypes ' + - 'library. See https://fb.me/react-warning-dont-call-proptypes ' + - 'for details.', - propFullName, - componentName - ); - manualPropTypeCallCache[cacheKey] = true; - } - } - } if (props[propName] == null) { var locationName = ReactPropTypeLocationNames[location]; if (isRequired) { @@ -205,13 +178,7 @@ function createChainableTypeChecker(validate) { } return null; } else { - return validate( - props, - propName, - componentName, - location, - propFullName, - ); + return validate(props, propName, componentName, location, propFullName); } } @@ -222,14 +189,7 @@ function createChainableTypeChecker(validate) { } function createPrimitiveTypeChecker(expectedType) { - function validate( - props, - propName, - componentName, - location, - propFullName, - secret - ) { + function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== expectedType) { @@ -276,8 +236,7 @@ function createArrayOfTypeChecker(typeChecker) { i, componentName, location, - `${propFullName}[${i}]`, - ReactPropTypesSecret + `${propFullName}[${i}]` ); if (error instanceof Error) { return error; @@ -368,8 +327,7 @@ function createObjectOfTypeChecker(typeChecker) { key, componentName, location, - `${propFullName}.${key}`, - ReactPropTypesSecret + `${propFullName}.${key}` ); if (error instanceof Error) { return error; @@ -391,14 +349,7 @@ function createUnionTypeChecker(arrayOfTypeCheckers) { for (var i = 0; i < arrayOfTypeCheckers.length; i++) { var checker = arrayOfTypeCheckers[i]; if ( - checker( - props, - propName, - componentName, - location, - propFullName, - ReactPropTypesSecret - ) == null + checker(props, propName, componentName, location, propFullName) == null ) { return null; } @@ -448,8 +399,7 @@ function createShapeTypeChecker(shapeTypes) { key, componentName, location, - `${propFullName}.${key}`, - ReactPropTypesSecret + `${propFullName}.${key}` ); if (error) { return error; diff --git a/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js b/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js index 9f8b991b54ceb..5b8a0c5a81389 100644 --- a/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js +++ b/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js @@ -15,7 +15,6 @@ var PropTypes; var React; var ReactFragment; var ReactTestUtils; -var ReactPropTypesSecret; var Component; var MyComponent; @@ -27,8 +26,6 @@ function typeCheckFail(declaration, value, message) { 'testProp', 'testComponent', 'prop', - null, - ReactPropTypesSecret ); expect(error instanceof Error).toBe(true); expect(error.message).toBe(message); @@ -81,38 +78,16 @@ function typeCheckPass(declaration, value) { 'testProp', 'testComponent', 'prop', - null, - ReactPropTypesSecret ); expect(error).toBe(null); } -function expectWarningInDevelopment(declaration, value) { - var props = {testProp: value}; - var propName = 'testProp' + Math.random().toString(); - var componentName = 'testComponent' + Math.random().toString(); - for (var i = 0; i < 3; i ++) { - declaration( - props, - propName, - componentName, - 'prop' - ); - } - expect(console.error.calls.count()).toBe(1); - expect(console.error.calls.argsFor(0)[0]).toContain( - 'You are manually calling a React.PropTypes validation ' - ); - console.error.calls.reset(); -} - describe('ReactPropTypes', () => { beforeEach(() => { PropTypes = require('ReactPropTypes'); React = require('React'); ReactFragment = require('ReactFragment'); ReactTestUtils = require('ReactTestUtils'); - ReactPropTypesSecret = require('ReactPropTypesSecret'); }); describe('Primitive Types', () => { @@ -184,52 +159,6 @@ describe('ReactPropTypes', () => { it('should warn for missing required values', () => { typeCheckFailRequiredValues(PropTypes.string.isRequired); }); - - it('should warn if called manually in development', () => { - spyOn(console, 'error'); - expectWarningInDevelopment(PropTypes.array, /please/); - expectWarningInDevelopment(PropTypes.array, []); - expectWarningInDevelopment(PropTypes.array.isRequired, /please/); - expectWarningInDevelopment(PropTypes.array.isRequired, []); - expectWarningInDevelopment(PropTypes.array.isRequired, null); - expectWarningInDevelopment(PropTypes.array.isRequired, undefined); - expectWarningInDevelopment(PropTypes.bool, []); - expectWarningInDevelopment(PropTypes.bool, true); - expectWarningInDevelopment(PropTypes.bool.isRequired, []); - expectWarningInDevelopment(PropTypes.bool.isRequired, true); - expectWarningInDevelopment(PropTypes.bool.isRequired, null); - expectWarningInDevelopment(PropTypes.bool.isRequired, undefined); - expectWarningInDevelopment(PropTypes.func, false); - expectWarningInDevelopment(PropTypes.func, function() {}); - expectWarningInDevelopment(PropTypes.func.isRequired, false); - expectWarningInDevelopment(PropTypes.func.isRequired, function() {}); - expectWarningInDevelopment(PropTypes.func.isRequired, null); - expectWarningInDevelopment(PropTypes.func.isRequired, undefined); - expectWarningInDevelopment(PropTypes.number, function() {}); - expectWarningInDevelopment(PropTypes.number, 42); - expectWarningInDevelopment(PropTypes.number.isRequired, function() {}); - expectWarningInDevelopment(PropTypes.number.isRequired, 42); - expectWarningInDevelopment(PropTypes.number.isRequired, null); - expectWarningInDevelopment(PropTypes.number.isRequired, undefined); - expectWarningInDevelopment(PropTypes.string, 0); - expectWarningInDevelopment(PropTypes.string, 'foo'); - expectWarningInDevelopment(PropTypes.string.isRequired, 0); - expectWarningInDevelopment(PropTypes.string.isRequired, 'foo'); - expectWarningInDevelopment(PropTypes.string.isRequired, null); - expectWarningInDevelopment(PropTypes.string.isRequired, undefined); - expectWarningInDevelopment(PropTypes.symbol, 0); - expectWarningInDevelopment(PropTypes.symbol, Symbol('Foo')); - expectWarningInDevelopment(PropTypes.symbol.isRequired, 0); - expectWarningInDevelopment(PropTypes.symbol.isRequired, Symbol('Foo')); - expectWarningInDevelopment(PropTypes.symbol.isRequired, null); - expectWarningInDevelopment(PropTypes.symbol.isRequired, undefined); - expectWarningInDevelopment(PropTypes.object, ''); - expectWarningInDevelopment(PropTypes.object, {foo: 'bar'}); - expectWarningInDevelopment(PropTypes.object.isRequired, ''); - expectWarningInDevelopment(PropTypes.object.isRequired, {foo: 'bar'}); - expectWarningInDevelopment(PropTypes.object.isRequired, null); - expectWarningInDevelopment(PropTypes.object.isRequired, undefined); - }); }); describe('Any type', () => { @@ -248,13 +177,6 @@ describe('ReactPropTypes', () => { it('should warn for missing required values', () => { typeCheckFailRequiredValues(PropTypes.any.isRequired); }); - - it('should warn if called manually in development', () => { - spyOn(console, 'error'); - expectWarningInDevelopment(PropTypes.any, null); - expectWarningInDevelopment(PropTypes.any.isRequired, null); - expectWarningInDevelopment(PropTypes.any.isRequired, undefined); - }); }); describe('ArrayOf Type', () => { @@ -342,24 +264,6 @@ describe('ReactPropTypes', () => { PropTypes.arrayOf(PropTypes.number).isRequired ); }); - - it('should warn if called manually in development', () => { - spyOn(console, 'error'); - expectWarningInDevelopment( - PropTypes.arrayOf({ foo: PropTypes.string }), - { foo: 'bar' } - ); - expectWarningInDevelopment( - PropTypes.arrayOf(PropTypes.number), - [1, 2, 'b'] - ); - expectWarningInDevelopment( - PropTypes.arrayOf(PropTypes.number), - {'0': 'maybe-array', length: 1} - ); - expectWarningInDevelopment(PropTypes.arrayOf(PropTypes.number).isRequired, null); - expectWarningInDevelopment(PropTypes.arrayOf(PropTypes.number).isRequired, undefined); - }); }); describe('Component Type', () => { @@ -432,18 +336,6 @@ describe('ReactPropTypes', () => { it('should warn for missing required values', () => { typeCheckFailRequiredValues(PropTypes.element.isRequired); }); - - it('should warn if called manually in development', () => { - spyOn(console, 'error'); - expectWarningInDevelopment(PropTypes.element, [
,
]); - expectWarningInDevelopment(PropTypes.element,
); - expectWarningInDevelopment(PropTypes.element, 123); - expectWarningInDevelopment(PropTypes.element, 'foo'); - expectWarningInDevelopment(PropTypes.element, false); - expectWarningInDevelopment(PropTypes.element.isRequired, null); - expectWarningInDevelopment(PropTypes.element.isRequired, undefined); - }); - }); describe('Instance Types', () => { @@ -518,15 +410,6 @@ describe('ReactPropTypes', () => { it('should warn for missing required values', () => { typeCheckFailRequiredValues(PropTypes.instanceOf(String).isRequired); }); - - it('should warn if called manually in development', () => { - spyOn(console, 'error'); - expectWarningInDevelopment(PropTypes.instanceOf(Date), {}); - expectWarningInDevelopment(PropTypes.instanceOf(Date), new Date()); - expectWarningInDevelopment(PropTypes.instanceOf(Date).isRequired, {}); - expectWarningInDevelopment(PropTypes.instanceOf(Date).isRequired, new Date()); - }); - }); describe('React Component Types', () => { @@ -625,16 +508,6 @@ describe('ReactPropTypes', () => { it('should accept empty array for required props', () => { typeCheckPass(PropTypes.node.isRequired, []); }); - - it('should warn if called manually in development', () => { - spyOn(console, 'error'); - expectWarningInDevelopment(PropTypes.node, 'node'); - expectWarningInDevelopment(PropTypes.node, {}); - expectWarningInDevelopment(PropTypes.node.isRequired, 'node'); - expectWarningInDevelopment(PropTypes.node.isRequired, undefined); - expectWarningInDevelopment(PropTypes.node.isRequired, undefined); - }); - }); describe('ObjectOf Type', () => { @@ -737,21 +610,6 @@ describe('ReactPropTypes', () => { PropTypes.objectOf(PropTypes.number).isRequired ); }); - - it('should warn if called manually in development', () => { - spyOn(console, 'error'); - expectWarningInDevelopment( - PropTypes.objectOf({ foo: PropTypes.string }), - { foo: 'bar' } - ); - expectWarningInDevelopment( - PropTypes.objectOf(PropTypes.number), - {a: 1, b: 2, c: 'b'} - ); - expectWarningInDevelopment(PropTypes.objectOf(PropTypes.number), [1, 2]); - expectWarningInDevelopment(PropTypes.objectOf(PropTypes.number), null); - expectWarningInDevelopment(PropTypes.objectOf(PropTypes.number), undefined); - }); }); describe('OneOf Types', () => { @@ -808,13 +666,6 @@ describe('ReactPropTypes', () => { it('should warn for missing required values', () => { typeCheckFailRequiredValues(PropTypes.oneOf(['red', 'blue']).isRequired); }); - - it('should warn if called manually in development', () => { - spyOn(console, 'error'); - expectWarningInDevelopment(PropTypes.oneOf(['red', 'blue']), true); - expectWarningInDevelopment(PropTypes.oneOf(['red', 'blue']), null); - expectWarningInDevelopment(PropTypes.oneOf(['red', 'blue']), undefined); - }); }); describe('Union Types', () => { @@ -879,23 +730,6 @@ describe('ReactPropTypes', () => { PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired ); }); - - it('should warn if called manually in development', () => { - spyOn(console, 'error'); - expectWarningInDevelopment( - PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - [] - ); - expectWarningInDevelopment( - PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - null - ); - expectWarningInDevelopment( - PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - undefined - ); - }); - }); describe('Shape Types', () => { @@ -975,21 +809,6 @@ describe('ReactPropTypes', () => { PropTypes.shape({key: PropTypes.number}).isRequired ); }); - - it('should warn if called manually in development', () => { - spyOn(console, 'error'); - expectWarningInDevelopment(PropTypes.shape({}), 'some string'); - expectWarningInDevelopment(PropTypes.shape({ foo: PropTypes.number }), { foo: 42 }); - expectWarningInDevelopment( - PropTypes.shape({key: PropTypes.number}).isRequired, - null - ); - expectWarningInDevelopment( - PropTypes.shape({key: PropTypes.number}).isRequired, - undefined - ); - expectWarningInDevelopment(PropTypes.element,
); - }); }); describe('Symbol Type', () => { diff --git a/src/renderers/dom/client/wrappers/LinkedValueUtils.js b/src/renderers/dom/client/wrappers/LinkedValueUtils.js index 94f16aa3ebfb1..3b6c0057f691d 100644 --- a/src/renderers/dom/client/wrappers/LinkedValueUtils.js +++ b/src/renderers/dom/client/wrappers/LinkedValueUtils.js @@ -12,7 +12,6 @@ 'use strict'; var React = require('React'); -var ReactPropTypesSecret = require('ReactPropTypesSecret'); var invariant = require('invariant'); var warning = require('warning'); @@ -110,8 +109,6 @@ var LinkedValueUtils = { propName, tagName, 'prop', - null, - ReactPropTypesSecret ); } if (error instanceof Error && !(error.message in loggedTypeFailures)) { diff --git a/src/shared/types/ReactPropTypesSecret.js b/src/shared/types/ReactPropTypesSecret.js deleted file mode 100644 index 0f47ff2afb919..0000000000000 --- a/src/shared/types/ReactPropTypesSecret.js +++ /dev/null @@ -1,17 +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 ReactPropTypesSecret - */ - -'use strict'; - -const ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'; - -module.exports = ReactPropTypesSecret; diff --git a/src/shared/types/checkReactTypeSpec.js b/src/shared/types/checkReactTypeSpec.js index 06c2904a7aac1..c9315a349cdf6 100644 --- a/src/shared/types/checkReactTypeSpec.js +++ b/src/shared/types/checkReactTypeSpec.js @@ -12,7 +12,6 @@ 'use strict'; var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames'); -var ReactPropTypesSecret = require('ReactPropTypesSecret'); var invariant = require('invariant'); var warning = require('warning'); @@ -73,7 +72,7 @@ function checkReactTypeSpec( ReactPropTypeLocationNames[location], typeSpecName ); - error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret); + error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location); } catch (ex) { error = ex; }