(type, source)
| 568 | }, {}); |
| 569 | |
| 570 | const getDefaultPropsForClassComponent = (type, source) => { |
| 571 | // For class component, the type has its own property, then get the |
| 572 | // first declaration and one of them will be either |
| 573 | // an ObjectLiteralExpression or an Identifier which get in the |
| 574 | // newChild with the proper props. |
| 575 | const defaultProps = type.getProperty('defaultProps'); |
| 576 | if (!defaultProps) { |
| 577 | return {}; |
| 578 | } |
| 579 | const decl = defaultProps.getDeclarations()[0]; |
| 580 | let propValues = {}; |
| 581 | |
| 582 | decl.getChildren().forEach(child => { |
| 583 | let newChild = child; |
| 584 | |
| 585 | if (ts.isIdentifier(child)) { |
| 586 | // There should be two identifier, the first is ignored. |
| 587 | const value = source.locals.get(child.escapedText); |
| 588 | if ( |
| 589 | value && |
| 590 | value.valueDeclaration && |
| 591 | ts.isVariableDeclaration(value.valueDeclaration) && |
| 592 | value.valueDeclaration.initializer |
| 593 | ) { |
| 594 | newChild = value.valueDeclaration.initializer; |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | const {properties} = newChild; |
| 599 | if (properties) { |
| 600 | propValues = getDefaultPropsValues(properties); |
| 601 | } |
| 602 | }); |
| 603 | return propValues; |
| 604 | }; |
| 605 | |
| 606 | const getProps = ( |
| 607 | properties, |
no test coverage detected
searching dependent graphs…