MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / propertyInitializer

Function propertyInitializer

src/resolution/frameworks/angular-router.ts:873–897  ·  view source on GitHub ↗
(owner: Node, name: string, content: string)

Source from the content-addressed store, hash-verified

871
872/** A class property's initializer, read from its body: `routerLinkAbout = publicRoutes.about.routerLink;`. */
873export function propertyInitializer(owner: Node, name: string, content: string): string | null {
874 const body = content.split('\n').slice(owner.startLine - 1, owner.endLine).join('\n');
875 const decl = new RegExp(String.raw`(?:^|[\s;{])(?:(?:public|private|protected|readonly|static|override)\s+)*${escapeRegExp(name)}\s*(?::[^=;\n]+)?=\s*`).exec(body);
876 if (!decl) return null;
877 let i = decl.index + decl[0].length;
878 const start = i;
879 while (i < body.length) {
880 const ch = body[i]!;
881 if (ch === '"' || ch === "'" || ch === '`') {
882 const end = skipString(body, i);
883 if (end < 0) return null;
884 i = end + 1;
885 continue;
886 }
887 if (ch === '[' || ch === '{' || ch === '(') {
888 const end = matchBracket(body, i);
889 if (end < 0) return null;
890 i = end + 1;
891 continue;
892 }
893 if (ch === ';' || ch === '\n') break;
894 i++;
895 }
896 return body.slice(start, i).trim() || null;
897}
898
899/** The array an arrow function returns: `(id) => ['/x', id]` or `(id) => { return ['/x', id]; }`. */
900function arrowReturn(fn: string): string | null {

Callers 1

destinationOfFunction · 0.85

Calls 5

escapeRegExpFunction · 0.90
skipStringFunction · 0.90
matchBracketFunction · 0.90
execMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected