(propType, propObj, parentType = null)
| 321 | }; |
| 322 | |
| 323 | const getPropType = (propType, propObj, parentType = null) => { |
| 324 | // Types can get namespace prefixes or not. |
| 325 | let name = checker.typeToString(propType).replace(/^React\./, ''); |
| 326 | let value, elements; |
| 327 | const raw = name; |
| 328 | |
| 329 | const newParentType = (parentType || []).concat(raw) |
| 330 | |
| 331 | if (propType.isUnion()) { |
| 332 | if (isUnionLiteral(propType)) { |
| 333 | return {...getEnum(propType), raw}; |
| 334 | } else if (raw.includes('|')) { |
| 335 | return {...getUnion(propType, propObj, newParentType), raw}; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | name = getPropTypeName(name); |
| 340 | |
| 341 | // Shapes & array support. |
| 342 | if (!PRIMITIVES.concat('enum', 'func', 'union').includes(name)) { |
| 343 | if ( |
| 344 | // Excluding object with arrays in the raw. |
| 345 | (name.includes('[]') && name.endsWith("]")) || |
| 346 | name.includes('Array') |
| 347 | ) { |
| 348 | name = 'arrayOf'; |
| 349 | const replaced = raw.replace('[]', ''); |
| 350 | if (unionSupport.includes(replaced)) { |
| 351 | // Simple types are easier. |
| 352 | value = { |
| 353 | name: getPropTypeName(replaced), |
| 354 | raw: replaced |
| 355 | }; |
| 356 | } else { |
| 357 | // Complex types get the type parameter (Array<type>) |
| 358 | const [nodeType] = checker.getTypeArguments(propType); |
| 359 | |
| 360 | if (nodeType) { |
| 361 | value = getPropType( |
| 362 | nodeType, propObj, newParentType, |
| 363 | ); |
| 364 | } else { |
| 365 | // Not sure, might be unsupported here. |
| 366 | name = 'array'; |
| 367 | } |
| 368 | } |
| 369 | } else if ( |
| 370 | name === 'tuple' || |
| 371 | (name.startsWith('[') && name.endsWith(']')) |
| 372 | ) { |
| 373 | name = 'tuple'; |
| 374 | elements = propType.resolvedTypeArguments.map( |
| 375 | t => getPropType(t, propObj, newParentType) |
| 376 | ); |
| 377 | } else if ( |
| 378 | BANNED_TYPES.includes(name) || |
| 379 | (parentType && parentType.includes(name)) |
| 380 | ) { |
no test coverage detected
searching dependent graphs…