(expr: string, file: string, owner: Node | null, context: ResolutionContext, depth: number, fromRoot: boolean)
| 935 | } |
| 936 | |
| 937 | function 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 |
no test coverage detected