13
13
14
14
var ReactElement = require ( 'ReactElement' ) ;
15
15
var ReactPropTypeLocationNames = require ( 'ReactPropTypeLocationNames' ) ;
16
+ var ReactPropTypesSecret = require ( 'ReactPropTypesSecret' ) ;
16
17
17
18
var emptyFunction = require ( 'emptyFunction' ) ;
18
19
var getIteratorFn = require ( 'getIteratorFn' ) ;
@@ -154,16 +155,42 @@ function PropTypeError(message) {
154
155
PropTypeError . prototype = Error . prototype ;
155
156
156
157
function createChainableTypeChecker ( validate ) {
158
+ if ( __DEV__ ) {
159
+ var manualPropTypeCallCache = { } ;
160
+ }
157
161
function checkType (
158
162
isRequired ,
159
163
props ,
160
164
propName ,
161
165
componentName ,
162
166
location ,
163
- propFullName
167
+ propFullName ,
168
+ secret
164
169
) {
165
170
componentName = componentName || ANONYMOUS ;
166
171
propFullName = propFullName || propName ;
172
+ if ( __DEV__ ) {
173
+ if (
174
+ secret !== ReactPropTypesSecret &&
175
+ typeof console !== 'undefined'
176
+ ) {
177
+ var cacheKey = `${ componentName } :${ propName } ` ;
178
+ if ( ! manualPropTypeCallCache [ cacheKey ] ) {
179
+ warning (
180
+ false ,
181
+ 'You are manually calling a React.PropTypes validation ' +
182
+ 'function for the `%s` prop on `%s`. This is deprecated ' +
183
+ 'and will not work in production with the next major version. ' +
184
+ 'You may be seeing this warning due to a third-party PropTypes ' +
185
+ 'library. See https://fb.me/react-warning-dont-call-proptypes ' +
186
+ 'for details.' ,
187
+ propFullName ,
188
+ componentName
189
+ ) ;
190
+ manualPropTypeCallCache [ cacheKey ] = true ;
191
+ }
192
+ }
193
+ }
167
194
if ( props [ propName ] == null ) {
168
195
var locationName = ReactPropTypeLocationNames [ location ] ;
169
196
if ( isRequired ) {
@@ -180,7 +207,13 @@ function createChainableTypeChecker(validate) {
180
207
}
181
208
return null ;
182
209
} else {
183
- return validate ( props , propName , componentName , location , propFullName ) ;
210
+ return validate (
211
+ props ,
212
+ propName ,
213
+ componentName ,
214
+ location ,
215
+ propFullName ,
216
+ ) ;
184
217
}
185
218
}
186
219
@@ -191,7 +224,14 @@ function createChainableTypeChecker(validate) {
191
224
}
192
225
193
226
function createPrimitiveTypeChecker ( expectedType ) {
194
- function validate ( props , propName , componentName , location , propFullName ) {
227
+ function validate (
228
+ props ,
229
+ propName ,
230
+ componentName ,
231
+ location ,
232
+ propFullName ,
233
+ secret
234
+ ) {
195
235
var propValue = props [ propName ] ;
196
236
var propType = getPropType ( propValue ) ;
197
237
if ( propType !== expectedType ) {
@@ -238,7 +278,8 @@ function createArrayOfTypeChecker(typeChecker) {
238
278
i ,
239
279
componentName ,
240
280
location ,
241
- `${ propFullName } [${ i } ]`
281
+ `${ propFullName } [${ i } ]` ,
282
+ ReactPropTypesSecret
242
283
) ;
243
284
if ( error instanceof Error ) {
244
285
return error ;
@@ -329,7 +370,8 @@ function createObjectOfTypeChecker(typeChecker) {
329
370
key ,
330
371
componentName ,
331
372
location ,
332
- `${ propFullName } .${ key } `
373
+ `${ propFullName } .${ key } ` ,
374
+ ReactPropTypesSecret
333
375
) ;
334
376
if ( error instanceof Error ) {
335
377
return error ;
@@ -351,7 +393,14 @@ function createUnionTypeChecker(arrayOfTypeCheckers) {
351
393
for ( var i = 0 ; i < arrayOfTypeCheckers . length ; i ++ ) {
352
394
var checker = arrayOfTypeCheckers [ i ] ;
353
395
if (
354
- checker ( props , propName , componentName , location , propFullName ) == null
396
+ checker (
397
+ props ,
398
+ propName ,
399
+ componentName ,
400
+ location ,
401
+ propFullName ,
402
+ ReactPropTypesSecret
403
+ ) == null
355
404
) {
356
405
return null ;
357
406
}
@@ -401,7 +450,8 @@ function createShapeTypeChecker(shapeTypes) {
401
450
key ,
402
451
componentName ,
403
452
location ,
404
- `${ propFullName } .${ key } `
453
+ `${ propFullName } .${ key } ` ,
454
+ ReactPropTypesSecret
405
455
) ;
406
456
if ( error ) {
407
457
return error ;
0 commit comments