MCPcopy Create free account
hub / github.com/Snapchat/Valdi / dumpInterface

Function dumpInterface

compiler/companion/src/AST.ts:697–763  ·  view source on GitHub ↗
(
  node: ts.InterfaceDeclaration | ts.ClassDeclaration,
  references: AST.TypeReferences,
  dumpMemberPredicate: (memberNode: ts.TypeElement | ts.ClassElement) => boolean = () => true,
)

Source from the content-addressed store, hash-verified

695}
696
697export 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;

Callers 3

AST.spec.tsFile · 0.90
getInterfaceASTMethod · 0.90
dumpRootNodesFunction · 0.85

Calls 7

getNodeCommentsFunction · 0.90
getIdentifierStringFunction · 0.85
parsePropertyLikeFunction · 0.85
parseTypeFunction · 0.85
getEndMethod · 0.80
mapMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected