(html: string, target: PatchTarget)
| 243 | } |
| 244 | |
| 245 | function findTagByClass(html: string, target: PatchTarget): TagMatch | null { |
| 246 | const classMatch = target.selector?.match(/^\.([a-zA-Z0-9_-]+)$/); |
| 247 | if (!classMatch) return null; |
| 248 | const cls = classMatch[1]; |
| 249 | const pattern = new RegExp( |
| 250 | `(<[^>]*\\bclass=(["'])[^"']*\\b${escapeRegex(cls)}\\b[^"']*\\2[^>]*)>`, |
| 251 | "gi", |
| 252 | ); |
| 253 | const selectorIndex = target.selectorIndex ?? 0; |
| 254 | let match: RegExpExecArray | null; |
| 255 | let currentIndex = 0; |
| 256 | while ((match = pattern.exec(html)) !== null) { |
| 257 | if (currentIndex === selectorIndex && match.index != null) { |
| 258 | return { |
| 259 | tag: match[1], |
| 260 | start: match.index, |
| 261 | end: match.index + match[1].length, |
| 262 | }; |
| 263 | } |
| 264 | currentIndex += 1; |
| 265 | } |
| 266 | return null; |
| 267 | } |
| 268 | |
| 269 | export function findTagByTarget(html: string, target: PatchTarget): TagMatch | null { |
| 270 | if (target.hfId) { |
no test coverage detected