MCPcopy
hub / github.com/CopilotKit/CopilotKit / visit

Method visit

scripts/docs/lib/source.ts:53–106  ·  view source on GitHub ↗
(node: ts.Node)

Source from the content-addressed store, hash-verified

51 let interfaceName: string = "";
52
53 const visit = (node: ts.Node) => {
54 // if we find a matching function declaration
55 if (
56 ts.isFunctionDeclaration(node) &&
57 node.name?.getText() === name &&
58 node.parameters.length &&
59 node.parameters[0].type &&
60 ts.isTypeReferenceNode(node.parameters[0].type)
61 ) {
62 interfaceName = node.parameters[0].type.typeName.getText();
63 }
64 // if we find a matching class declaration
65 else if (ts.isClassDeclaration(node) && node.name?.getText() === name) {
66 const constructor = node.members.find((member) =>
67 ts.isConstructorDeclaration(member),
68 ) as ts.ConstructorDeclaration;
69 if (
70 constructor &&
71 constructor.parameters.length &&
72 constructor.parameters[0].type &&
73 ts.isTypeReferenceNode(constructor.parameters[0].type)
74 ) {
75 interfaceName = constructor.parameters[0].type.typeName.getText();
76 }
77 }
78 // if we find a matching forwardRef declaration
79 else if (ts.isVariableStatement(node) || ts.isVariableDeclaration(node)) {
80 const declarations = ts.isVariableStatement(node)
81 ? node.declarationList.declarations
82 : [node];
83
84 declarations.forEach((declaration) => {
85 if (
86 ts.isVariableDeclaration(declaration) &&
87 declaration.name.getText() === name &&
88 declaration.initializer &&
89 ts.isCallExpression(declaration.initializer) &&
90 declaration.initializer.expression.getText() === "React.forwardRef"
91 ) {
92 const func = declaration.initializer.arguments[0];
93 if (
94 ts.isArrowFunction(func) &&
95 func.parameters.length &&
96 func.parameters[0].type &&
97 ts.isTypeReferenceNode(func.parameters[0].type)
98 ) {
99 interfaceName = func.parameters[0].type.typeName.getText();
100 }
101 }
102 });
103 }
104
105 ts.forEachChild(node, visit);
106 };
107
108 // analyze the source file
109 visit(this.sourceFile);

Callers

nothing calls this directly

Calls 9

findTypeDeclarationMethod · 0.95
parseMethod · 0.95
forEachMethod · 0.80
pushMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected