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

Function destinationOf

src/resolution/frameworks/angular-router.ts:937–976  ·  view source on GitHub ↗
(expr: string, file: string, owner: Node | null, context: ResolutionContext, depth: number, fromRoot: boolean)

Source from the content-addressed store, hash-verified

935}
936
937function destinationOf(expr: string, file: string, owner: Node | null, context: ResolutionContext, depth: number, fromRoot: boolean): HrefLiteral | null {
938 const text = expr.trim();
939 if (text.length === 0 || depth > 4) return null;
940 if (text[0] === '[') return commandsHref(text, fromRoot);
941 const literal = staticString(text);
942 if (literal !== null) return toHref(literal);
943 // `'/editor/' + article.slug`: the literal head, a hole for the rest.
944 if (/^['"]/.test(text) && text.includes('+')) {
945 const head = staticString(text.slice(0, text.indexOf('+')));
946 if (head !== null && head.startsWith('/')) return toHref(head.replace(/\/?$/, '/') + HOLE);
947 }
948 // `this.routerLinkAdminControlUsers.concat(userId)`: one segment more.
949 const concat = /^(.*?)\.concat\s*\((.*)\)$/s.exec(text);
950 if (concat) {
951 const base = angularDestination(concat[1]!, file, owner, context, depth + 1, fromRoot);
952 const added = concat[2]!.split(',').filter((a) => a.trim().length > 0).length;
953 return base && added > 0 ? toHref(base.path.replace(/\/$/, '') + ('/' + HOLE).repeat(added)) : base;
954 }
955 // `update.routerLink(dataSource, symbol)`: a route constant that builds its
956 // commands — its returned array, the arguments holes.
957 const call = /^((?:this\s*\.\s*)?[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)+)\s*\((.*)\)$/s.exec(text);
958 if (call) {
959 const fn = constantText(call[1]!.replace(/\s+/g, '').replace(/^this\./, ''), file, context);
960 const returned = fn ? arrowReturn(fn) : null;
961 return returned ? commandsHref(returned, fromRoot) : null;
962 }
963 const chain = /^(?:this\s*\.\s*)?([A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)*)$/.exec(text);
964 if (!chain) return parseHrefExpression(text);
965 const parts = chain[1]!.replace(/\s+/g, '').split('.');
966 const content = context.readFile(file);
967 if (content && owner && (text.startsWith('this') || parts.length === 1)) {
968 const init = propertyInitializer(owner, parts[0]!, content);
969 if (init !== null) {
970 if (parts.length === 1) return angularDestination(init, file, owner, context, depth + 1, fromRoot);
971 return angularDestination(`${init}.${parts.slice(1).join('.')}`, file, owner, context, depth + 1, fromRoot);
972 }
973 }
974 const constant = constantText(parts.join('.'), file, context);
975 return constant ? angularDestination(constant, file, owner, context, depth + 1, fromRoot) : null;
976}
977
978// =============================================================================
979// The resolver

Callers 1

angularDestinationFunction · 0.85

Calls 11

toHrefFunction · 0.90
parseHrefExpressionFunction · 0.90
commandsHrefFunction · 0.85
staticStringFunction · 0.85
angularDestinationFunction · 0.85
constantTextFunction · 0.85
arrowReturnFunction · 0.85
propertyInitializerFunction · 0.85
execMethod · 0.65
readFileMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected