(text: string)
| 130 | * links. Null when any part is computed. |
| 131 | */ |
| 132 | export function staticString(text: string): string | null { |
| 133 | const parts: string[] = []; |
| 134 | let rest = text.trim(); |
| 135 | while (rest.length > 0) { |
| 136 | let part: string | null = null; |
| 137 | let used = 0; |
| 138 | const q = rest[0]; |
| 139 | if (q === '"' || q === "'") { |
| 140 | part = readStringAt(rest, 0); |
| 141 | used = part === null ? 0 : skipString(rest, 0) + 1; |
| 142 | } else if (rest.startsWith('$localize')) { |
| 143 | const tick = rest.indexOf('`'); |
| 144 | const end = tick < 0 ? -1 : skipString(rest, tick); |
| 145 | if (end > 0) { |
| 146 | part = localizeDefault(rest.slice(0, end + 1)); |
| 147 | used = end + 1; |
| 148 | } |
| 149 | } else if (q === '`') { |
| 150 | const end = skipString(rest, 0); |
| 151 | const body = end > 0 ? rest.slice(1, end) : ''; |
| 152 | if (end > 0 && !body.includes('${')) { |
| 153 | part = body; |
| 154 | used = end + 1; |
| 155 | } |
| 156 | } |
| 157 | if (part === null || used === 0) return null; |
| 158 | parts.push(part); |
| 159 | rest = rest.slice(used).trim(); |
| 160 | if (rest.length === 0) break; |
| 161 | if (rest[0] !== '+') return null; |
| 162 | rest = rest.slice(1).trim(); |
| 163 | } |
| 164 | return parts.length > 0 ? parts.join('') : null; |
| 165 | } |
| 166 | |
| 167 | /** A route's own path segment(s): a string, a `$localize` default, or a constant kept as `{expr}`; null when it cannot be named. */ |
| 168 | function pathSegments(text: string): string[] | null { |
no test coverage detected