( node: ts.InterfaceDeclaration | ts.ClassDeclaration, references: AST.TypeReferences, dumpMemberPredicate: (memberNode: ts.TypeElement | ts.ClassElement) => boolean = () => true, )
| 695 | } |
| 696 | |
| 697 | export function dumpInterface( |
| 698 | node: ts.InterfaceDeclaration | ts.ClassDeclaration, |
| 699 | references: AST.TypeReferences, |
| 700 | dumpMemberPredicate: (memberNode: ts.TypeElement | ts.ClassElement) => boolean = () => true, |
| 701 | ): AST.Interface | undefined { |
| 702 | if (!node.name) { |
| 703 | return undefined; |
| 704 | } |
| 705 | |
| 706 | const name = getIdentifierString(node.name); |
| 707 | |
| 708 | const members: AST.PropertyLikeDeclaration[] = []; |
| 709 | |
| 710 | const typeParameters = node.typeParameters?.map((tsTypeParam) => { |
| 711 | return { |
| 712 | start: node.getStart(), |
| 713 | end: node.getEnd(), |
| 714 | name: getIdentifierString(tsTypeParam.name), |
| 715 | }; |
| 716 | }); |
| 717 | |
| 718 | for (const member of node.members) { |
| 719 | if (!member.name) { |
| 720 | continue; |
| 721 | } |
| 722 | |
| 723 | if (!dumpMemberPredicate(member)) { |
| 724 | continue; |
| 725 | } |
| 726 | |
| 727 | const propertyLike = parsePropertyLike(member, references); |
| 728 | members.push(propertyLike); |
| 729 | } |
| 730 | |
| 731 | const result: AST.Interface = { |
| 732 | start: node.getStart(), |
| 733 | end: node.getEnd(), |
| 734 | name, |
| 735 | members, |
| 736 | typeParameters, |
| 737 | }; |
| 738 | |
| 739 | if (node.heritageClauses?.length) { |
| 740 | const supertypes: AST.SuperTypeClause[] = []; |
| 741 | for (const heritageClause of node.heritageClauses) { |
| 742 | for (const type of heritageClause.types) { |
| 743 | const outputType = parseType(type, references); |
| 744 | |
| 745 | supertypes.push({ |
| 746 | start: type.getStart(), |
| 747 | end: type.getEnd(), |
| 748 | isImplements: heritageClause.token === ts.SyntaxKind.ImplementsKeyword, |
| 749 | type: outputType, |
| 750 | }); |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | result.supertypes = supertypes; |
no test coverage detected