(s: string, at: number)
| 237 | * with every `${…}` replaced by {@link HOLE}. Null when `at` is not a string. |
| 238 | */ |
| 239 | export function readStringAt(s: string, at: number): string | null { |
| 240 | const q = s[at]; |
| 241 | if (q === '"' || q === "'") { |
| 242 | let out = ''; |
| 243 | for (let i = at + 1; i < s.length; i++) { |
| 244 | const ch = s[i]!; |
| 245 | if (ch === '\\') { |
| 246 | out += s[i + 1] ?? ''; |
| 247 | i++; |
| 248 | continue; |
| 249 | } |
| 250 | if (ch === q) return out; |
| 251 | out += ch; |
| 252 | } |
| 253 | return null; |
| 254 | } |
| 255 | if (q === '`') { |
| 256 | const end = skipTemplate(s, at); |
| 257 | let out = ''; |
| 258 | for (let i = at + 1; i < end; i++) { |
| 259 | const ch = s[i]!; |
| 260 | if (ch === '\\') { |
| 261 | out += s[i + 1] ?? ''; |
| 262 | i++; |
| 263 | continue; |
| 264 | } |
| 265 | if (ch === '$' && s[i + 1] === '{') { |
| 266 | let depth = 0; |
| 267 | for (i = i + 1; i < end; i++) { |
| 268 | if (s[i] === '{') depth++; |
| 269 | else if (s[i] === '}') { |
| 270 | depth--; |
| 271 | if (depth === 0) break; |
| 272 | } |
| 273 | } |
| 274 | out += HOLE; |
| 275 | continue; |
| 276 | } |
| 277 | out += ch; |
| 278 | } |
| 279 | return out; |
| 280 | } |
| 281 | return null; |
| 282 | } |
| 283 | |
| 284 | export interface HrefLiteral { |
| 285 | /** The path part, `${…}` holes kept as {@link HOLE}; query and hash removed. */ |
no test coverage detected