@@ -21,16 +21,10 @@ import {
21
21
REACT_FRAGMENT_TYPE ,
22
22
REACT_ELEMENT_TYPE ,
23
23
} from 'shared/ReactSymbols' ;
24
- import { warnAboutSpreadingKeyToJSX } from 'shared/ReactFeatureFlags' ;
25
24
import checkPropTypes from 'shared/checkPropTypes' ;
26
25
27
26
import ReactCurrentOwner from './ReactCurrentOwner' ;
28
- import {
29
- isValidElement ,
30
- createElement ,
31
- cloneElement ,
32
- jsxDEV ,
33
- } from './ReactElement' ;
27
+ import { isValidElement , createElement , cloneElement } from './ReactElement' ;
34
28
import { setCurrentlyValidatingElement } from './ReactDebugCurrentFrame' ;
35
29
36
30
let propTypesMisspellWarningShown ;
@@ -39,8 +33,6 @@ if (__DEV__) {
39
33
propTypesMisspellWarningShown = false ;
40
34
}
41
35
42
- const hasOwnProperty = Object . prototype . hasOwnProperty ;
43
-
44
36
function getDeclarationErrorAddendum ( ) {
45
37
if ( ReactCurrentOwner . current ) {
46
38
const name = getComponentName ( ReactCurrentOwner . current . type ) ;
@@ -261,137 +253,6 @@ function validateFragmentProps(fragment) {
261
253
}
262
254
}
263
255
264
- export function jsxWithValidation (
265
- type ,
266
- props ,
267
- key ,
268
- isStaticChildren ,
269
- source ,
270
- self ,
271
- ) {
272
- const validType = isValidElementType ( type ) ;
273
-
274
- // We warn in this case but don't throw. We expect the element creation to
275
- // succeed and there will likely be errors in render.
276
- if ( ! validType ) {
277
- let info = '' ;
278
- if (
279
- type === undefined ||
280
- ( typeof type === 'object' &&
281
- type !== null &&
282
- Object . keys ( type ) . length === 0 )
283
- ) {
284
- info +=
285
- ' You likely forgot to export your component from the file ' +
286
- "it's defined in, or you might have mixed up default and named imports." ;
287
- }
288
-
289
- const sourceInfo = getSourceInfoErrorAddendum ( source ) ;
290
- if ( sourceInfo ) {
291
- info += sourceInfo ;
292
- } else {
293
- info += getDeclarationErrorAddendum ( ) ;
294
- }
295
-
296
- let typeString ;
297
- if ( type === null ) {
298
- typeString = 'null' ;
299
- } else if ( Array . isArray ( type ) ) {
300
- typeString = 'array' ;
301
- } else if ( type !== undefined && type . $$typeof === REACT_ELEMENT_TYPE ) {
302
- typeString = `<${ getComponentName ( type . type ) || 'Unknown' } />` ;
303
- info =
304
- ' Did you accidentally export a JSX literal instead of a component?' ;
305
- } else {
306
- typeString = typeof type ;
307
- }
308
-
309
- if ( __DEV__ ) {
310
- console . error (
311
- 'React.jsx: type is invalid -- expected a string (for ' +
312
- 'built-in components) or a class/function (for composite ' +
313
- 'components) but got: %s.%s' ,
314
- typeString ,
315
- info ,
316
- ) ;
317
- }
318
- }
319
-
320
- const element = jsxDEV ( type , props , key , source , self ) ;
321
-
322
- // The result can be nullish if a mock or a custom function is used.
323
- // TODO: Drop this when these are no longer allowed as the type argument.
324
- if ( element == null ) {
325
- return element ;
326
- }
327
-
328
- // Skip key warning if the type isn't valid since our key validation logic
329
- // doesn't expect a non-string/function type and can throw confusing errors.
330
- // We don't want exception behavior to differ between dev and prod.
331
- // (Rendering will throw with a helpful message and as soon as the type is
332
- // fixed, the key warnings will appear.)
333
-
334
- if ( validType ) {
335
- const children = props . children ;
336
- if ( children !== undefined ) {
337
- if ( isStaticChildren ) {
338
- if ( Array . isArray ( children ) ) {
339
- for ( let i = 0 ; i < children . length ; i ++ ) {
340
- validateChildKeys ( children [ i ] , type ) ;
341
- }
342
-
343
- if ( Object . freeze ) {
344
- Object . freeze ( children ) ;
345
- }
346
- } else {
347
- if ( __DEV__ ) {
348
- console . error (
349
- 'React.jsx: Static children should always be an array. ' +
350
- 'You are likely explicitly calling React.jsxs or React.jsxDEV. ' +
351
- 'Use the Babel transform instead.' ,
352
- ) ;
353
- }
354
- }
355
- } else {
356
- validateChildKeys ( children , type ) ;
357
- }
358
- }
359
- }
360
-
361
- if ( __DEV__ ) {
362
- if ( warnAboutSpreadingKeyToJSX ) {
363
- if ( hasOwnProperty . call ( props , 'key' ) ) {
364
- console . error (
365
- 'React.jsx: Spreading a key to JSX is a deprecated pattern. ' +
366
- 'Explicitly pass a key after spreading props in your JSX call. ' +
367
- 'E.g. <%s {...props} key={key} />' ,
368
- getComponentName ( type ) || 'ComponentName' ,
369
- ) ;
370
- }
371
- }
372
- }
373
-
374
- if ( type === REACT_FRAGMENT_TYPE ) {
375
- validateFragmentProps ( element ) ;
376
- } else {
377
- validatePropTypes ( element ) ;
378
- }
379
-
380
- return element ;
381
- }
382
-
383
- // These two functions exist to still get child warnings in dev
384
- // even with the prod transform. This means that jsxDEV is purely
385
- // opt-in behavior for better messages but that we won't stop
386
- // giving you warnings if you use production apis.
387
- export function jsxWithValidationStatic ( type , props , key ) {
388
- return jsxWithValidation ( type , props , key , true ) ;
389
- }
390
-
391
- export function jsxWithValidationDynamic ( type , props , key ) {
392
- return jsxWithValidation ( type , props , key , false ) ;
393
- }
394
-
395
256
export function createElementWithValidation ( type , props , children ) {
396
257
const validType = isValidElementType ( type ) ;
397
258
0 commit comments