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

Function commandsHref

src/resolution/frameworks/angular-router.ts:807–859  ·  view source on GitHub ↗
(text: string, fromRoot = false)

Source from the content-addressed store, hash-verified

805
806/** The destination a command array names: `['/article', slug]` is `/article/${…}`; null when it is relative or not a literal array. */
807export function commandsHref(text: string, fromRoot = false): HrefLiteral | null {
808 const arr = text.trim();
809 if (arr[0] !== '[') return null;
810 const close = matchBracket(arr, 0);
811 if (close < 0) return null;
812 const parts: string[] = [];
813 let i = 1;
814 let element = '';
815 const flush = (): boolean => {
816 const e = element.trim();
817 element = '';
818 if (e.length === 0) return true;
819 const literal = staticString(e);
820 if (literal !== null) {
821 parts.push(...literal.split('/').filter((seg) => seg.length > 0));
822 return true;
823 }
824 // A matrix-params object says nothing about the path.
825 if (e.startsWith('{')) return true;
826 parts.push(HOLE);
827 return true;
828 };
829 while (i < close) {
830 const ch = arr[i]!;
831 if (ch === '"' || ch === "'" || ch === '`') {
832 const end = skipString(arr, i);
833 if (end < 0) return null;
834 element += arr.slice(i, end + 1);
835 i = end + 1;
836 continue;
837 }
838 if (ch === '[' || ch === '{' || ch === '(') {
839 const end = matchBracket(arr, i);
840 if (end < 0) return null;
841 element += arr.slice(i, end + 1);
842 i = end + 1;
843 continue;
844 }
845 if (ch === ',') flush();
846 else element += ch;
847 i++;
848 }
849 flush();
850 // Only an absolute destination: `['/login']`. In a template, `['../', id]`
851 // and a bare `['edit']` are relative to wherever the component is; a
852 // `router.navigate(['project', 'issue', id])` with no `relativeTo` starts
853 // from the root.
854 const firstElement = arr.slice(1, close).split(',')[0] ?? '';
855 const first = staticString(firstElement);
856 if (first === null || (!first.startsWith('/') && !(fromRoot && !first.startsWith('.')))) return null;
857 const pathText = '/' + parts.filter((p) => p.length > 0).join('/');
858 return namesSomewhere({ path: pathText, display: pathText.split(HOLE).join('${…}') });
859}
860
861/**
862 * The href, when it names at least one segment of its own. A path made only

Callers 2

destinationOfFunction · 0.85

Calls 6

matchBracketFunction · 0.90
skipStringFunction · 0.90
staticStringFunction · 0.85
namesSomewhereFunction · 0.85
flushFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected