Skip to content

Commit

Permalink
Revert "Revert "Warn if PropType function is called manually (faceboo…
Browse files Browse the repository at this point in the history
…k#7132)""

This reverts commit be71f76.

In other words, now we again have the warning if you attempt to call PropTypes manually.
It was removed in facebook#8066 but we shouldn't have done this since we still want to avoid people accidentally calling them in production (and even more so since now it would throw).

Fixes facebook#8080.
  • Loading branch information
gaearon committed Feb 7, 2017
1 parent e280f5a commit 38d19b9
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 8 deletions.
64 changes: 57 additions & 7 deletions src/isomorphic/classic/types/ReactPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

var ReactElement = require('ReactElement');
var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames');
var ReactPropTypesSecret = require('ReactPropTypesSecret');

var emptyFunction = require('emptyFunction');
var getIteratorFn = require('getIteratorFn');
Expand Down Expand Up @@ -154,16 +155,42 @@ function PropTypeError(message) {
PropTypeError.prototype = Error.prototype;

function createChainableTypeChecker(validate) {
if (__DEV__) {
var manualPropTypeCallCache = {};
}
function checkType(
isRequired,
props,
propName,
componentName,
location,
propFullName
propFullName,
secret
) {
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) {
Expand All @@ -180,7 +207,13 @@ function createChainableTypeChecker(validate) {
}
return null;
} else {
return validate(props, propName, componentName, location, propFullName);
return validate(
props,
propName,
componentName,
location,
propFullName,
);
}
}

Expand All @@ -191,7 +224,14 @@ function createChainableTypeChecker(validate) {
}

function createPrimitiveTypeChecker(expectedType) {
function validate(props, propName, componentName, location, propFullName) {
function validate(
props,
propName,
componentName,
location,
propFullName,
secret
) {
var propValue = props[propName];
var propType = getPropType(propValue);
if (propType !== expectedType) {
Expand Down Expand Up @@ -238,7 +278,8 @@ function createArrayOfTypeChecker(typeChecker) {
i,
componentName,
location,
`${propFullName}[${i}]`
`${propFullName}[${i}]`,
ReactPropTypesSecret
);
if (error instanceof Error) {
return error;
Expand Down Expand Up @@ -329,7 +370,8 @@ function createObjectOfTypeChecker(typeChecker) {
key,
componentName,
location,
`${propFullName}.${key}`
`${propFullName}.${key}`,
ReactPropTypesSecret
);
if (error instanceof Error) {
return error;
Expand All @@ -351,7 +393,14 @@ function createUnionTypeChecker(arrayOfTypeCheckers) {
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
var checker = arrayOfTypeCheckers[i];
if (
checker(props, propName, componentName, location, propFullName) == null
checker(
props,
propName,
componentName,
location,
propFullName,
ReactPropTypesSecret
) == null
) {
return null;
}
Expand Down Expand Up @@ -401,7 +450,8 @@ function createShapeTypeChecker(shapeTypes) {
key,
componentName,
location,
`${propFullName}.${key}`
`${propFullName}.${key}`,
ReactPropTypesSecret
);
if (error) {
return error;
Expand Down
Loading

0 comments on commit 38d19b9

Please sign in to comment.