(owner: Node, name: string, content: string)
| 871 | |
| 872 | /** A class property's initializer, read from its body: `routerLinkAbout = publicRoutes.about.routerLink;`. */ |
| 873 | export 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]; }`. */ |
| 900 | function arrowReturn(fn: string): string | null { |
no test coverage detected